Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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
Node.js 发送HTTP请求时,我有一个错误消息头内容包含无效字符_Node.js_Request_Http Headers_Axios - Fatal编程技术网

Node.js 发送HTTP请求时,我有一个错误消息头内容包含无效字符

Node.js 发送HTTP请求时,我有一个错误消息头内容包含无效字符,node.js,request,http-headers,axios,Node.js,Request,Http Headers,Axios,我有一个函数getBody,它从url获取body,在某个url上(我不知道具体是哪一个),我总是得到错误: _http_outgoing.js:494 throw new TypeError('The header content contains invalid characters'); 这些URL大多包含丹麦口音字符,这可能是个问题。我设置了标题:“内容类型”:“文本/普通”;字符集=UTF-8',将字符集设置为UTF-8。可能是头主机出了问题 我尝试过使用punycode,或

我有一个函数getBody,它从url获取body,在某个url上(我不知道具体是哪一个),我总是得到错误:

_http_outgoing.js:494
    throw new TypeError('The header content contains invalid characters');
这些URL大多包含丹麦口音字符,这可能是个问题。我设置了标题:“内容类型”:“文本/普通”;字符集=UTF-8',将字符集设置为UTF-8。可能是头主机出了问题

我尝试过使用punycode,或url,它将url转换为ASCII,但这些转换后的url不起作用

function getBody(n) {
    var url = n; //urls[n];
    url = (url.indexOf('http://')==-1 && url.indexOf('https://')==-1) ? 'http://'+url : url;
    instance.get(url,
        {
            headers: {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
                'Content-Type': 'text/plain; charset=UTF-8'

            },
        }
}