tags:

views:

469

answers:

1

i looked at the api but i could not find it.

where/how should i put data on a POST request on client.request() client.requets("POST" ..)?

thanks

+2  A: 

Maybe you should look closer then.

This is straight from the node.js API documentation:

request_headers is optional. Additional request headers might be added internally by Node. Returns a ClientRequest object.

Do remember to include the Content-Length header if you plan on sending a body. If you plan on streaming the body, perhaps set Transfer-Encoding: chunked.

NOTE: the request is not complete. This method only sends the header of the request. One needs to call request.end() to finalize the request and retrieve the response. (This sounds convoluted but it provides a chance for the user to stream a body to the server with request.write().)

request.write() is for sending data.

So you do it like this (more or less):

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

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

This code is just here to get the concept across. I have NOT tested it in any way.

Techpriester