-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjmri.js
More file actions
45 lines (37 loc) · 956 Bytes
/
Copy pathjmri.js
File metadata and controls
45 lines (37 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var http = require('http');
var parser = require('xml2json');
function xmlioRequest(host,port,parms,callback) {
var postData = parser.toXml(parms);
var postOptions = {
host: host,
port: port,
path: '/xmlio',
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'Content-Length': postData.length
}
};
var responseXML = [];
var req = http.request(postOptions, function(res) {
res.setEncoding('utf8');
res.on('data', function (dataChunk) {
responseXML.push(dataChunk);
});
res.on('end',function () {
var jsonData = parser.toJson(responseXML.toString());
console.log(responseXML.toString());
console.log(jsonData);
if (typeof(callback) == 'function') {
callback(jsonData);
}
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
console.log('sending: '+postData);
req.write(postData);
req.end();
}
exports.xmlioRequest = xmlioRequest;