开始学习 Node.js,用 Node.js 发送POST
请求:
var http = require('http')
, https = require('https')
, _ = require('underscore')
, querystring = require('querystring');
// Client constructor ...
Client.prototype.request = function (options) {
_.extend(options, {
hostname: Client.API_ENDPOINT,
path: Client.API_PATH,
headers: {
'user-agent': this.agent
}
});
var req = (this.secure ? https : http).request(options);
if(options.data) req.write(querystring.stringify(options.data));
req.end();
req.on('response', function (res) {
res.on('data', function (chunk) {
res.body += chunk;
});
res.on('end', function () {
console.log(res.body);
});
});
}
身体表现:undefined<xml version="1.0" encoding="UTF-8">
。
那undefined
是从哪里来的?