Node.js POST Request

I looked at the api but could not find it.

Where / How should I put data in a POST request on client.request()or client.request("POST" ,...)?

+5
source share
3 answers

Maybe you should come closer.

This is straight from the node.js API documentation:

request_headers is optional. Additional request headers can be added internally by node. Returns a ClientRequest Object.

Remember to include the Content-Length Header if you plan on sending the body. If you are planning a streaming body, you may have installed Encoding: chunked.

: . . request.end() . ( , request.write().)

request.write() .

, ( ):

var rq = client.request('POST', 'http://example.org/', {'Content-Length': '1024'});
var body = getMe1024BytesOfData();

rq.write(body);
rq.end();

, . - .

+8

request . API.

+1

Requestify, HTTP-, nodeJS +, .

POST :

var requestify = require('requestify');

requestify.post('http://example.com', {
    hello: 'world'
})
.then(function(response) {
    // Get the response body (JSON parsed or jQuery object for XMLs)
    response.getBody();
});
0

All Articles