-
Notifications
You must be signed in to change notification settings - Fork 1
/
post_request.js
39 lines (34 loc) · 1.07 KB
/
post_request.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
var http = require('http');
var options = {
hostname: 'localhost',
port: 3000,
path: '/users/adduser',
method: 'POST',
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 (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
//write data to request body
usuario = {};
usuario.username = "jeymisson";
usuario.password = "asdf";
usuario.email = "[email protected]";
usuario.profile = {};
usuario.profile.name = "jeymisson";
usuario.profile.age = 25;
usuario.profile.profilePic = "url://sfa";
usuario.profile.gender = 1;
usuario.profile.degree = "superior incompleto";
usuario.profile.speciality = "Ciencia da computacao";
usuario.profile.subjects = [];
req.write(JSON.stringify(usuario));
req.end();