2017-07-03 7 views
1

http getからinitレスポンスを読み込むにはどうすればよいですか?基本的に私のコードはこれですが、私はこれらのオブジェクトに到達できません。http get requestからの応答を読む

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 




    }); 

レスポンスがhttps://www.npmjs.com/package/request

からその

IncomingMessage { 
    _readableState: 
    ReadableState { 
    objectMode: false, 
    highWaterMark: 16384, 
    buffer: BufferList { head: null, tail: null, length: 0 }, 
    length: 0, 
    pipes: null, 
},.../// continues... 
+0

のように、bodyのparamから結果にアクセスすることができますか? – evolutionxbox

+0

私はあなたがアクセスしようとしているものは身体だと思います、ボディはエンドポイントから返された実際のデータを含んでいます。応答はhttp.IncomingMessageオブジェクト(応答オブジェクト)です。あなたはそれについてもっと読むことができますhttps://nodejs.org/api/http.html#http_class_http_incomingmessage –

+0

私はそれの中にいくつかのデータを持っている可能性があるinit応答に到達しようとしています。私はどのようにして配列データを見つけることができますか?応答 – user8198887

答えて

2

のようなものです、あなたはあなたの応答を返している何本

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. 
}); 
関連する問題