Last active
December 16, 2015 19:59
-
-
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!
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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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