我使用cURL(或节点request
)并看到散布在整个回复中的\u0000
,并且不明白它们出现的原因。
我发现我可以用response.body.replace(/\u0000/g, '')
删除它们,但想了解它的来源,看看是否有更好的方法。
我已经玩过请求标题,但不知道这些字符来自哪里。
此外,当我在浏览器中浏览网站时,我看不到它们,并将请求(chrome'复制为cURL选项)复制到终端中,我确实看到了它们。
是否有一些请求标头或其他方式我应该删除/检测这些unicode字符?
使用节点request
的示例请求标头:
{ 'Content-Type': '*/*; charset=utf-8',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
}
示例cURL (我的~/.curlrc
为空):
curl 'http://example.com' -H 'Pragma: no-cache' -H 'DNT: 1' \
-H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,la;q=0.6' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --compressed
回复标题:
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 04 Nov 2017 14:50:13 GMT
Content-Type: text/plain
Last-Modified: Thu, 02 Nov 2017 19:02:13 GMT
Transfer-Encoding: chunked
Connection: close
ETag: W/"59fc6be1-41e2"
Content-Encoding: gzip