nodeJS中写function调取接口 并返回获取的数据
async function getUser() {
//获取UserID
var datas ={CultureName: 'zh-CN', EntCode: '1001', OrgCode: 'SD001', UserCode: 'admin'}
//bodyString 数据
var arrList = {
context : datas,
appID:9221508317,
pushProgram: "ASN单",
senderSys: 1
}
var bodyString = JSON.stringify(arrList)
var options = {
host: '10.108.21.13',
port: 80,
path: 'XXXXXXXXX',
method: 'POST',
headers:{
'Content-Type':'application/json',
'Content-Length':bodyString.length
}
};
var Remark;
let req=http.request(options,function(res){
res.setEncoding('utf-8');
let UserresponseStringS = '';
res.on('data', function(data) {
// return data;
UserresponseStringS += data;
var responseStrings1 = JSON.parse(UserresponseStringS) ;
var Strings1 = JSON.parse(responseStrings1.d) ;
console.log('-----resBody-----',Strings1);
Remark = Strings1.Result;
console.log('-----Remark -----',Remark ); //Remark 可正常打印
});
res.on('end', function() {
console.log('-----resBody-----',UserresponseStringS);
});
req.on('error', function(e) {
// TODO: handle error.
console.log('-----error-------',e);
});
});
req.write(bodyString);
req.end();
}