標籤:ack search windows name new ant 驗證 post api
處理了很多天,終於使用Nodejs可以發出請求至WebAPI,能夠正常處理資料了
首先加入npm包
npm install httpntlm
在app.js中加入代碼
var httpntlm = require(‘httpntlm‘);var fs = require(‘fs‘);var options = { url: ‘http://getnt130.gfg1.esquel.com/InstantNoodle_SIT/Workbench/api/v1/styleproduct/1/1‘, username: ‘chenwes‘, password: ‘[email protected]‘, domain: ‘gfg1‘, 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
nodejs擷取WebAPI(Windows驗證)