如何从http get中读取init响应?基本上我的代码就是这个,但我无法达到这些目标。
var request = require("request")
request({
url: "http://xxx/xxx/get.php?act=init&aparam=parame",
method:"get",
json: true
}, function (error, response, body) {
console.log(response.toJSON);// why i cant reach every object etc from here like this
});
响应就像那样
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
},.../// continues...
答案 0 :(得分:2)
来自https://www.npmjs.com/package/request
您可以访问body
param的结果,例如
var request = require('request');
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});