Skip to content

Instantly share code, notes, and snippets.

@Chrysweel
Last active December 16, 2015 19:59
Show Gist options
  • Save Chrysweel/5489407 to your computer and use it in GitHub Desktop.
Save Chrysweel/5489407 to your computer and use it in GitHub Desktop.
How Can I send object with Http.request ?? The call with "curl" works correctly!
In my config is:
"url": {
"host": "localhost",
"path": "/workspace/xxx",
"method": "GET",
"headers": {
"accept": "application/json"
}
}
--------------------
var options = this.server.config.url;
options.method = "POST";
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
req.write('{"User":{"name":"peter"}}');
req.end();
@Chrysweel
Copy link
Author

This call with curl works.

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"User":{"name":"peter"}}' http://localhost/workspace/xxxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment