doc: http.request() improved code example

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Guilherme de Souza
2014-09-12 06:25:15 -03:00
committed by Trevor Norris
parent 7ca5af87a0
commit 468fb547bb

View File

@@ -489,11 +489,19 @@ upload a file with a POST request, then write to the `ClientRequest` object.
Example:
var postData = querystring.stringify({
'msg' : 'Hello World!'
});
var options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var req = http.request(options, function(res) {
@@ -510,8 +518,7 @@ Example:
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.write(postData);
req.end();
Note that in the example `req.end()` was called. With `http.request()` one