【发布时间】:2020-05-03 12:11:31
【问题描述】:
我在使用 NodeJS 的 api 调用时遇到问题。我用 postman 没问题,但是当我用 Node 运行它时,服务器响应是 401。
这是 nodejs 代码:
var request = require("request");
var options = { method: 'GET',
url: 'https://api.cardmarket.com/ws/v2.0/output.json/products/find',
qs:
{ search: 'Salamangrande%25Loup%25Du%25Soleil',
idGame: '3',
idLanguage: '2' },
headers:
{ 'cache-control': 'no-cache',
Connection: 'keep-alive',
Cookie: 'PHPSESSID=m399v2el9635i3jq0e4did8f5k',
'Accept-Encoding': 'gzip, deflate',
Host: 'api.cardmarket.com',
'Postman-Token': '9b19a85d-8888-4f31-8d24-fe309a55bf76,4d8f4741-4b85-4d5e-85dc-8ac43ea5f56c',
'Cache-Control': 'no-cache',
Accept: '*/*',
'User-Agent': 'PostmanRuntime/7.19.0',
Authorization: 'OAuth realm="https%3A%2F%2Fapi.cardmarket.com%2Fws%2Fv2.0%2Foutput.json%2Fproducts%2Ffind",oauth_consumer_key="xxxxxxxxx",oauth_token="xxxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1579186959",oauth_nonce="vWUKBoTTkle",oauth_version="1.0",oauth_signature="ZD2TwzLVHqOjLm3u%2BWv%2FsQ8mdfs%3D"' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
});
所以基本上这是我的(完美工作)。
知道语法有什么问题或如何在标头中正确实现 oauth 签名吗?
【问题讨论】:
-
您使用请求的
oauthoption 为您构建oauth 参数字符串是否得到不同的结果?
标签: node.js api oauth get httprequest