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 badges1 Answer
Reset to default 8var 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
版权声明:本文标题:javascript - How to send a POST request with data and with bearer authorization in node.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743874677a2554113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论