【发布时间】:2018-01-30 00:02:23
【问题描述】:
我想通过请求模块使用 euc-kr 字符集将表单数据发送到某个网站。我也使用 iconv-lite 模块,因为 nodejs 支持的字符集并不多。
无论如何,网站使用euc-kr 字符集,所以我必须处理表单数据的编码(节点的默认字符集是utf-8)。但是效果不太好,我尝试了很多次更改一些选项,但我一直坚持到现在,所以你能告诉我一些提示吗?
// added module request, iconv-lite(extendNodeEncoding) already.
function postDocumentForm() {
//Lets configure and request
request({
url: 'http://finance.naver.com/item/board_act.nhn', //URL to hit
headers: {
'Content-Type': 'content=text/html; charset=euc-kr'
},
method: 'POST',
encoding: 'euc-kr',
form: {
code:'000215',
mode: 'write',
temp: '',
keyCount: '0',
title: "폼 데이터 중 일부가 한글일 때",
opinion: '0',
body:'인코딩이 제대로 되지 않고 있음!'
}
}, function (error, response, body) {
if (error) {
console.log(error);
} else {
iconv.undoExtendNodeEncodings();
console.log(response.statusCode, response.body);
}
});
}
这是结果,奇怪的字符。
我试过了:
euc-kr to binary
euc-kr to null
euc-kr to utf-8
delete encoding option
delete request header
【问题讨论】:
标签: node.js character-encoding request