Skip to content

Instantly share code, notes, and snippets.

@bandicoot86
Created November 22, 2013 11:31
Show Gist options
  • Save bandicoot86/7598487 to your computer and use it in GitHub Desktop.
Save bandicoot86/7598487 to your computer and use it in GitHub Desktop.
Nodejs rest request
var http = require('http');
var data = JSON.stringify({
'id': '2'
});
var options = {
host: 'localhost',
port: '8094',
path: '/spring-rest-core/service/api/vv',
method: 'GET',
headers: {
'Content-Type': 'application/json; charset=utf-8',
}
};
var req = http.request(options, function(res) {
var msg = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
msg += chunk;
});
console.log('Msg '+ msg);
res.on('end', function() {
console.log(JSON.parse(msg));
}).on('error', function(e){
console.log('Got error ' + e.message);
});
});
req.write(data);
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment