【发布时间】:2017-09-16 00:19:59
【问题描述】:
我正在尝试从服务器的响应正文中提取数据。我已经浏览了一段时间的互联网,发现了一些“应该”工作但没有工作的东西。该请求是一个返回 JSON 对象的 https 请求。
//Open the request:
request({
//Set the request Method:
method: 'POST',
//Set the headers:
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer "+ token,
'X-Originating-Ip': ipAddress
},
//Set the URL:
url: 'URL',
//Set the request body:
body: { 'Body here'},
}, function(error, response, body){
//Alert the response body:
for(var i=0; body.data.listings.length; i++){
console.log(data.listings[i].listingType);
}
console.log(response.statusCode);
});
出于安全原因,我无法显示实际的响应正文,但它是一个包含多个数组的 JSON 对象。
【问题讨论】:
标签: json node.js api npm https