Parent: [18557b] (diff)

Child: [83d640] (diff)

Download this file

httpRequest.js    44 lines (39 with data), 1.1 kB

 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
/*made by Miguel Rodrigues @ KBZ miguel.rodrigues@knowledgebiz.pt*/
//httpRequest to send Notification by HTTP Request
var http = require("http");
module.exports.sendHttpRequest = function (hostname, port, path, method, notification) {
/*
var options = {
hostname: 'teste.proxy.beeceptor.com',
port: 80,
path: '/my/api/path',
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
*/
var options = {
hostname: hostname,
port: port,
path: path,
method: method,
headers: {
'Content-Type': 'application/json',
}
};
var req = http.request(options, function(res) {
console.log('Status: ' + res.statusCode);
console.log('Headers: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (body) {
console.log('Body: ' + body);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
notification = "'"+notification+"'";
req.write(notification);
req.end();
}