Node.js 将访问令牌传递给节点中的API
我通过开发一个应用程序来学习Node,该应用程序将访问相关服务器并提取其数据。 在这里,由于相关服务器需要传递访问令牌,我被卡住了,并且我无法成功提取数据 这是我的密码Node.js 将访问令牌传递给节点中的API,node.js,Node.js,我通过开发一个应用程序来学习Node,该应用程序将访问相关服务器并提取其数据。 在这里,由于相关服务器需要传递访问令牌,我被卡住了,并且我无法成功提取数据 这是我的密码 var options = { method: 'GET', url: 'any url', auth : { accessToken : "token here" }, headers: {
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);
}
您正在使用哪个httpClient?请求,取回;Axios?我正在使用请求作为httpClient