如何把这个curl请求转到一个node.js请求?

我有这个curl请求工作,我希望把它变成node.js代码。

curl -H "Content-Type: application/json" -X POST -d '{"text":"ibm","date":{"from":"20170330","to":"20170530"},"restrictedDateRange":false}' https://finsights.mybluemix.net/api/query 

然而,我尝试了我的方式,但我确信我做了错误的响应正文不符合我从curl请求中得到的。

我的代码失败了:

 server.get('/hello', function create(req, res, next) { // //sample request request({ url: "https://finsights.mybluemix.net/api/query", method: "POST", headers: { "content-type": "application/json", data: { "text": "ibm", "date": { "from": "20170330", "to": "20170530" }, "restrictedDateRange": "false", } }, json: true, // <--Very important!!! }, function(err, res, body) { console.log(body); }); // //end of sample request console.log("success"); return next(); }); 

请谁能教我如何改造它?

您的数据不应该是标题。 尝试在请求正文中包含您的数据,如下所示:

 request({ url: "https://finsights.mybluemix.net/api/query", method: "POST", headers: { "content-type": "application/json" }, body: { "text": "ibm", "date": { "from": "20170330", "to": "20170530" }, "restrictedDateRange": "false", }, json: true }, function(err, res, body) { console.log(body); });