简体   繁体   English

Node.js请求帖子带有主体包括api键

[英]Nodejs request post with body include api key

I have been trying about a week but I couldn't make a post request to get a result. 我已经尝试了大约一个星期,但无法发出发布请求以获取结果。 I tried a bunch of middlewares (exp: 'request', 'axios', 'reqclient','superagent etc..) but I couldn't make it. 我尝试了一堆中间件(例如:“ request”,“ axios”,“ reqclient”,“ superagent等”),但我做不到。

Please provide me a simple post request with sending API key and body. 请向我提供一个简单的发布请求,并发送API密钥和正文。

I also read all the documentation. 我还阅读了所有文档。

Please check below to see what I want : 请在下面查看我想要的内容:

*Authentication API key required. *需要验证API密钥。

*O-Auth Scopes trades * O-Auth范围交易

*Input One of: user_id + token or user_url is required. *输入以下项之一:user_id +令牌或user_url。


here is my one of try : 这是我的尝试之一:

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);
      });

I am getting this output : 我得到这个输出:

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

I tried some other request post middle-wares and played with content-type (application/json. dataForm, x-www-form-urlencoded) or 我尝试了其他一些请求发布中间件,并使用内容类型(application / json。dataForm,x-www-form-urlencoded)或

changed the location of my API key from header to body or 将我的API密钥的位置从标头更改为正文或

tried my API key inside of auth{authorization: "API Key"} 在auth {authorization:“ API Key”}中尝试了我的API密钥

tried much more. 尝试了更多。

the result didn't change. 结果没有改变。 I got the same output or errors. 我得到了相同的输出或错误。

EDIT : 编辑:

this is the link that I am trying to do but got stack : check here 这是我尝试做的链接,但是有堆栈: 请在此处检查

Solved ! 解决了 ! Everything works great. 一切正常。 Problem was I needed to send my API Key base64 string. 问题是我需要发送我的API密钥base64字符串。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM