处理了很多天,终于使用Nodejs可以发出请求至WebAPI,能够正常处理数据了
首先加入npm包
npm install httpntlm
在app.js中加入代码
var httpntlm = require('httpntlm'); var fs = require('fs'); var options = { url: 'http://get001.mygroup.com/InstantNoodle_SIT/Workbench/api/v1/styleproduct/1/1', username: 'chenwes', password: '999', domain: 'gfg8', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, json: { "filterType": "LEAF", "filters": [ {} ], "attributeName": "item_number", "searchOperator": "eq", "filterValue": "15CNLI001CL" } }; return new Promise(function (resolve, reject) { httpntlm.post(options, function (err, resp) { if (err) { reject(err); } console.log(resp.headers); console.log('-----------------------------------------'); console.log(resp.body); fs.writeFile("http.html", resp.body, function (err) { if (err) { return console.log(err); } console.log("The file was saved!"); }); }); });
参考:https://www.npmjs.com/package/httpntlm
http://stackoverflow.com/questions/33153979/how-to-post-data-using-node-http-ntlm