mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
committed by
Trevor Norris
parent
7ca5af87a0
commit
468fb547bb
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user