Node JS发布请求给出400,而Postman起作用

时间:2018-08-28 22:20:53

标签: javascript node.js post postman

我是使用nodejs的新手,并且遇到了这个看似微不足道的问题,下面粘贴的节点JS代码为我要进行的POST调用提供了400:

jsonObjectJira = JSON.stringify({
      "XXXXXX": {
            "id": "XXX"
          }
        });

console.log(jsonObjectJira);

//prepare the header for the JIRA request
var postheadersjira = {
 'authorization' : 'XXXXXX',
 'cache-control' : 'no-cache',
 'content-type' : 'application/json',
};

//the post options
var optionspostjira = {
 host : 'XX.XXX.XX.XXX',
 port : XXXX,
 path : 'rest/api/2/issue/XXXXX/transitions',
 method : 'POST',
 headers : postheadersjira
};

//do the PUT call
var reqPostJira = http.request(optionspostjira, function(resjira) {
 console.log("statusCode: ", resjira.statusCode);
 // uncomment it for header details
console.log("headers: ", resjira.headers);

 resjira.on('data', function(d1) {
     console.info('PUT result:\n');
     process.stdout.write(d1);
     console.info('\n\PUT completed via NodeJS');
 });
});

console.log("JSON: ", jsonObjectJira);
//write the json data
reqPostJira.write(jsonObjectJira);
reqPostJira.end();
reqPostJira.on('error', function(e) {
 console.error(e);
});

})

enter code here

从具有相同标头的POSTMAN进行的相同调用可以正常工作。这里有明显的问题吗?

0 个答案:

没有答案