nodejs 下post代码
var options = {
host: 'www.yourdomain.com',
post: 80,
method: 'POST',
path: '/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': params.length
}
};
var request = http.request(options, function(response) {
response.setEncoding('utf8');
response.on('data', function(chunk) {
console.log(chunk);
});
});
request.write(params);
request.end();
上一篇: Linux 下批量替换的命令
2011/12/18 21:54:16
看来你没有理解:’Content-Type’: ‘application/x-www-form-urlencoded’,
这句的含义。
urlencoded后的字符,是不可能存在中文字符的,全部是ascii码的字符。
所以params.length不会有错误的。
2011/12/17 17:42:36
强烈建议别写 ‘Content-Length’: params.length这句,如果params中包含中文,这个length是错误的,会导致发送的报文不完整。