我已成功使用python请求库调用API。需要在node.js中发出相同的请求。在SO上看到各种Q& As并尝试使用node.js中的请求库,但是无法使这项工作成为可能。有数据和不记名授权。
答案 0 :(得分:6)
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