我正在通过开发将访问相关服务器并提取其数据的应用程序来学习Node。在这里,由于相关服务器要求传递访问令牌,我陷入了困境,但我无法成功提取数据。
这是我的代码
var options = {
method: 'GET',
url: 'any url',
auth : {
accessToken : "token here"
},
headers: {
'Accept': 'application/json'
}
}
但是这样做我得到了错误错误:未定义身份验证机制
访问令牌似乎很完美。
很抱歉是否已经被问到,但我似乎找不到直接的答案。
感谢您的努力和时间。
尝试一下:
var req = {
host: 'YOUR_URL',
method: 'GET',
headers: {
Authorization: your token
'Content-Type': 'application/json'
}
}
request(req, 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);
}