POST request with data in node.js
How could I send POST request with data (eg. some variables) to the https server and display 开发者_Go百科the results to the end user?
Use the http.Client
module. From the docs:
var http = require('http');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/', {'host': 'www.google.com'});
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
I am pretty sure that you can exchange GET
with POST
;)
精彩评论