带有 body 的 Nodejs 请求 post 包含 api 键

Nodejs request post with body include api key

我已经尝试了大约一个星期,但无法发出 post 请求以获得结果。 我尝试了一堆中间件(exp:'request'、'axios'、'reqclient'、'superagent 等..)但我做不到。

请提供一个简单的 post 请求,发送 API 密钥和 body。

我也阅读了所有文档。

请在下面查看我想要的内容:

*Authentication API key required.

*O-Auth Scopes trades

*Input One of: user_id + token or user_url is required.


这是我的尝试之一:

const request = require('request-promise')

    const options = {
        method: 'POST',
        uri: 'api-site.com/Offer/v1/',
        headers: {
          'User-Agent': 'Request-Promise',
          'Authorization': 'Basic 123123asdasd123123'
        },
        body: {
            user_url: "site.com/user/user1234123",
            otherparams: "parameter"
          },
          json: true 
      };

      request(options)
      .then(function (response) {
        Console.log(response);
      })
      .catch(function (err) {
        console.log('Error ', err.message);
      });

我得到这个输出:

Error  : 401 - {"status":401,"time":1540458426,"message":"API Key Required"}

我尝试了一些其他请求 post middle-wares 并使用了 content-type (application/json.dataForm, x-www-form-urlencoded) 或

将我的 API 键的位置从 header 更改为 body 或

在 auth{authorization: "API Key"}

中尝试了我的 API 密钥

尝试了更多。

结果没有改变。我得到了相同的输出或错误。

编辑:

这是我正在尝试执行但得到堆栈的 link: check here

已解决! 一切都很好。问题是我需要发送我的 API 密钥 base64 字符串。

Buffer.from("your_api_key_value" + ":", "ascii").toString("base64")