Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created November 14, 2010 09:04
Show Gist options
  • Save KOBA789/676029 to your computer and use it in GitHub Desktop.
Save KOBA789/676029 to your computer and use it in GitHub Desktop.
localhost:3000にPOSTで"reqbody=あいう漢字"を飛ばすコード
var http = require('http');
var reqbody = 'reqbody=' + encodeURIComponent('あいう漢字');
var localhost = http.createClient(3000, 'localhost');
var request = localhost.request('POST', '/',
{
'host': 'localhost',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': reqbody.length
}
);
request.write(reqbody);
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment