我试图通过发送 token 和 header 从 API 中获取响应'content-type': 'application/json'
,但我不知道应该将它们放在哪里。
到目前为止,这是我的代码:
var request = require('request');
request.get('google example url', {
//
'auth': {
'bearer': '15252727282'
},
"headers": {
"Content-Type": "application/json"
}
}, 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);
});
这就是我在控制台中返回的内容:
error: null
statusCode: 401
body: HTTP Token: Access denied.