简体   繁体   English

带有post的node.js请求模块承载auth

[英]node.js request module bearer auth with post

I'm totally stuck here. 我完全被困在这里。 I need to post data to an API with bearer authentification. 我需要使用承载身份验证将数据发布到API。

I am using the request module in node.js . 我在node.js中使用请求模块。 The request documentation only describes the get method. 请求文档仅描述了get方法。 But I need a "POST". 但是我需要一个“ POST”。

request.get('http://some.server.com/', {
  'auth': {
    'bearer': 'bearerToken'
  }
});

Something like this (which of course is not working, otherwise I wouldn't post this question): 像这样的东西(这当然是行不通的,否则我不会发布这个问题):

request.post('http://some.server.com/', {
  'auth': {
    'timeout': 1000,
    'bearer': 'bearerToken',
    'body': '{SomeSerializedJSON}'
  }
});

Any clues? 有什么线索吗?

We need some more informations here ! 我们在这里需要更多信息!

Did you already sign in and have your bearer token ? 您是否已经登录并获得了承载令牌?

Moreover if there is no POST method in your targeted API you won't be able to use POST, you have to use the GET method implemented by their developers because this is how they want to receive the data. 此外,如果目标API中没有POST方法,则将无法使用POST,则必须使用由开发人员实现的GET方法,因为这是他们想要接收数据的方式。

And finally I will say that you may not need POST method, GET and POST can both transmit data to your API, the way of doing it is just different ( HTTP Methods GET vs POST by w3c ). 最后我要说的是,您可能不需要POST方法,GET和POST都可以将数据传输到您的API,只是方式不同( w3c的HTTP Methods GET vs POST )。

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

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