admin管理员组

文章数量:1352266

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but not able to make this work esp. with data and bearer authorization.

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but not able to make this work esp. with data and bearer authorization.

Share Improve this question edited Feb 4, 2018 at 12:37 rajesh-nitc asked Jan 31, 2018 at 7:06 rajesh-nitcrajesh-nitc 5,5494 gold badges29 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8
var request = require('request');
data = {
    "Inputs": {
            "input1":
            [
                {
                        'Col1': "5",   
                        'Col2': "3.5",   
                        'Col3': "1.5",   
                        'Col4': "0.2",   
                        'Col5': "doesnotmatter",   
                }
            ],
    },
"GlobalParameters":  {
}
}


var options = {
  method: 'POST',
  body: data,
  json: true,
  url: 'https://api.github./repos/request/request',
  headers: {
    'Authorization':'Bearer xxxx'
  }
};

function callback(error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body)
  }
}
//call the request

request(options, callback);

For more refference you can go to request library repo.headers

本文标签: javascriptHow to send a POST request with data and with bearer authorization in nodejsStack Overflow