使用本机“http”模块的 HTTP 请求的响应正文显示 unicode 字符的问号字符,而不是其实际值。这是我正在运行的基本代码片段。
var http = require('http');
var google = http.createClient(80, 'www.google.it');
var request = google.request('GET', '/',
{
'host': 'www.google.it',
}
);
request.end();
request.on('response', function (response) {
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log(chunk);
});
});
响应中有一个以“开头的特定单词”公开“。它的最后一个字母是一个奇怪的字符,对我来说显示为问号。这个词应该是公共性,而是显示为公开的?.
我也尝试过使用输出数据.toString()
:
console.log(chunk.toString());
or
console.log(chunk.toString('utf8'));
但我得到了相同的结果。
任何想法?
I set response.setEncoding('binary');
它有效。但不知道为什么。
参考:http://groups.google.com/group/nodejs/browse_thread/thread/3bd3935b1f42a5f4?pli=1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)