我已经成功地能够使用 python requests 库调用 API。需要在node.js中发出相同的请求。看到了关于 SO 的各种问答,并努力尝试使用 node.js 中的请求库,但无法使这项工作特别是。具有数据和承载授权。
最佳答案
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.com/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);
如需更多引用,您可以访问request
库存储库。 headers
关于javascript - 如何在node.js中发送带有数据和不记名授权的POST请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536410/