Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript js请求将umlauts转换为࿽;_Javascript_Node.js_Encoding - Fatal编程技术网

Javascript js请求将umlauts转换为࿽;

Javascript js请求将umlauts转换为࿽;,javascript,node.js,encoding,Javascript,Node.js,Encoding,我正在对web服务执行以下请求(使用request/request): return request.postAsync({ url, charset: 'Cp1252', // I also tried utf-8 encoding: null, // // I also tried Cp1252 -> unknown encoding, // I also tried utf-8 and nothing at all headers: {

我正在对web服务执行以下请求(使用request/request):

return request.postAsync({
    url,
    charset: 'Cp1252', // I also tried utf-8
    encoding: null, //
    // I also tried Cp1252 -> unknown encoding,
    // I also tried utf-8 and nothing at all
    headers: {
         "Accept": "application/octet-stream, text, text/plain, text/xml",
         "Accept-Encoding": "UTF-8",
         'Content-Type': "text/plain; charset=Cp1252;", // also tried utf-8, ISO-8859-1
         "User-Agent": "me"
    }
}).spread((res, body) => {
    body = body.toString();  // I also tried without toString();
    let ws = fs.createWriteStream('hhh.csv');
    ws.write(body);
    ws.end();
无论我做什么,umlauts都会变成

这些是web服务发回的标题:

'content-type': 'text; charset=Cp1252',
'content-length': '1895980',
vary: 'Accept-Encoding,User-Agent'
我试了好几天,一点运气都没有。我做错了什么

以下是迄今为止未能解决我问题的问题/答案列表:

是否是以下原因之一导致我的输入字符串不是UTF-8

let hash = crypto.createHmac("sha256", this.options.Signer);
this.query['Signature'] = hash.update(stringToSign).digest("base64");
签名者是一个字符串,包含
0-9
a-z
a-z
+
/


这个。查询['Signature']
是URL的一部分。

我最终解决了它,使用并将请求的编码“”设置为
null
,使其返回正文作为缓冲区。以下是我现在的工作配置:

return request.getAsync({
        url,
        encoding: null,
        headers: {
            "Accept": "text, text/plain, text/xml",
            "Accept-Encoding": "UTF-8",
            'Content-Type': "text/plain; charset=utf-8;",
            "User-Agent": "me"
        }
    }).spread((res, body) => {
        let a = iconv.decode(new Buffer(body), 'cp1252');
        // now a is holding a string with correct Umlauts and ß

您发送的确切字符是什么?它们当前是如何编码的?它们的当前字符集是什么?在umlaut“仍然”umlaut的位置。node js请求将umlaut转换为�" "不管我做什么,乌姆劳特都会变成�." --- 这些短语的意思是什么?您发送的确切字符是什么?它们当前是如何编码的?它们的当前字符集是什么?您是否尝试过更改您的
defaultEncoding
?即
fs.createWriteStream('hhh.csv',{defaultEncoding:'utf8'});
相关: