Created
November 22, 2013 11:31
-
-
Save bandicoot86/7598487 to your computer and use it in GitHub Desktop.
Nodejs rest request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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