requests.js
900 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
var http = require('http');
function postRequest(path, data) {
var options = {
host: path.hostname,
port: path.port,
path: path.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
var requesting = http.request(options, function(res) {
/* Debugging */
console.log('== Chamando callback: ' + path.hostname)
console.log('=== Response status: ' + res.statusCode);
console.log('=== Response headers: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('=== Response body: ' + chunk);
});
});
requesting.on('error', function (e) {
console.log("=== Não foi possível chamar a URL de callback");
});
requesting.write(data);
requesting.end();
}
module.exports.postRequest = postRequest;