-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpLib.js
43 lines (34 loc) · 1008 Bytes
/
httpLib.js
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
const https = require('https');
var parseString = require('xml2js').parseString;
exports.getRequestXML = function(req, callback) {
https.get(req, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
parseString(data, function (err, result) {
callback(result);
});
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
exports.getRequestJson = function(req, callback) {
https.get(req, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
callback(JSON.parse(data));
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}