简体   繁体   中英

node.js request module bearer auth with post

I'm totally stuck here. I need to post data to an API with bearer authentification.

I am using the request module in node.js . The request documentation only describes the get method. But I need a "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.

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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