gpt4 book ai didi

javascript - 读取来自 http get 请求的响应

转载 作者:行者123 更新时间:2023-11-30 15:12:43 24 4
gpt4 key购买 nike

我如何从 http get 读取初始响应?基本上我的代码是这样的,但我无法访问这些对象。

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...

最佳答案

来自 https://www.npmjs.com/package/request

你可以从 body 参数访问结果,像这样

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.
});

关于javascript - 读取来自 http get 请求的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44882245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com