Created
November 14, 2010 09:04
-
-
Save KOBA789/676029 to your computer and use it in GitHub Desktop.
localhost:3000にPOSTで"reqbody=あいう漢字"を飛ばすコード
This file contains 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 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