-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
51 lines (46 loc) · 1.22 KB
/
client.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
44
45
46
47
48
49
50
var https = require('https');
var http = require('http');
var url = require('url');
var qs = require('querystring');
var config = require('./config');
function jsonGet(options, callback) {
console.log({get: options});
var request = https.get(options, function(response) {
var body = '';
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
console.log({getResponse: body});
callback(JSON.parse(body));
});
response.on('close', function(err) {
console.log({close:err});
});
});
request.end();
}
function jsonPost(options, content, callback) {
console.log({post: content});
options.headers = {
'Content-Length': content.length,
'Content-Type': 'application/x-www-form-urlencoded'
};
var request = https.request(options, function(response) {
var body = '';
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
console.log({postResponse: body});
callback(JSON.parse(body));
});
response.on('close', function(err) {
console.log({close:err});
});
});
request.write(content);
request.end();
}
exports.get = jsonGet;
exports.post = jsonPost;