gpt4 book ai didi

xml - 如何借助node.js发送xml post参数

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:34 26 4
gpt4 key购买 nike

尝试通过 Node js 将 XML 数据发布到以下网址:-

var request = require("request");
var utf8 = require('utf8');



var abc = '<ENVELOPE><HEADER><TALLYREQUEST>Export Data</TALLYREQUEST></HEADER><BODY><EXPORTDATA><REQUESTDESC><REPORTNAME>Stock Summary</REPORTNAME><STATICVARIABLES><EXPLODEFLAG>Yes</EXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE></STATICVARIABLES></REQUESTDESC></EXPORTDATA></BODY></ENVELOPE>';

request.post({
url:"http://192.168.1.148",
port: 9000,
method:"POST",
headers:{
'Content-Type': 'application/xml',
},
body: abc
},
function(error, response, body){
console.log(response.statusCode);
console.log(body);
console.log(error);
});

但是解释器显示以下错误:-

console.log(response.statusCode);
^
TypeError: Cannot read property 'statusCode' of undefined
at Request._callback (C:\Users\bliscar\prog10.js:18:25)
at self.callback (C:\Users\bliscar\node_modules\request\request.js:198:22)
at Request.emit (events.js:107:17)
at Request.onRequestError (C:\Users\bliscar\node_modules\request\request.js:

861:8) at ClientRequest.emit (events.js:107:17) at Socket.socketErrorListener (_http_client.js:271:9) at Socket.emit (events.js:107:17) at net.js:459:14 at process._tickCallback (node.js:355:11)

无法找出问题所在。请帮忙解决。

最佳答案

试试这个:-

    var request = require("request");
var utf8 = require('utf8');



var abc = '<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<STATUS>1</STATUS>
</HEADER>
</ENVELOPE><ENVELOPE><HEADER><TALLYREQUEST>Export Data</TALLYREQUEST></HEADER><BODY><EXPORTDATA><REQUESTDESC><REPORTNAME>Stock Summary</REPORTNAME><STATICVARIABLES><EXPLODEFLAG>Yes</EXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE></STATICVARIABLES></REQUESTDESC></EXPORTDATA></BODY></ENVELOPE>';

request.post({
url:"http://192.168.1.148",
port: 9000,
method:"POST",
headers:{
'Content-Type': 'application/xml',
},
body: abc
},
function(error, response, body){
console.log(response.statusCode);
console.log(body);
console.log(error);
});

基本上在 xml 中添加计数的版本控制。它不会显示任何错误并且 xml 将同步

关于xml - 如何借助node.js发送xml post参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31703346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com