Reputation: 125
Trying to post XML data to following url via node js:-
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);
});
But interpreter is showing following 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)
Not able to work out what's the issue. Please help to resolve.
Upvotes: 3
Views: 15569
Reputation: 128
Try this :-
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);
});
Basically add versioning of tally in your xml. It won't show any error and xml will be synced
Upvotes: 11
Reputation: 2381
response is udnefined. This usualy happens when the server did not respond to the request.
Upvotes: 0