我有一个简单的 Node 脚本来处理来 self 的家庭自动化 API 的一些数据。一切正常,直到最后一次 Node 更新。现在,对于 Node 版本 4.3.0 或 5.6.0,http 模块给我这个错误:
{ [Error: Parse Error] bytesParsed: 193, code: 'HPE_UNEXPECTED_CONTENT_LENGTH' }
导致错误的 API 调用示例,它只返回一个数字(温度):
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 5
Content-Type: application/json
Transfer-Encoding: chunked
21.81
以及重现错误的代码:
const http = require("http");
const url = "http://127.0.0.1:8083/ZWaveAPI/Run/devices[11].instances[2].commandClasses[49].data[1].val.value";
http.get(url, (res) => {
// consume response body
res.resume();
}).on("error", (e) => {
console.log(e);
});
我认为该错误与 CVE-2016-2216 Response Splitting Vulnerability 有关,但我尝试运行带有 --security-revert=CVE-2016-2216 标志的脚本,但没有帮助。有什么想法吗?
最佳答案
我找到了这个 commit log .问题似乎是 Content-Length
和 Transfer-encoding: chunked
header 同时存在:
the server is sending both a Content-Length header and a Transfer-Encoding: chunked header, which is a violation of the HTTP spec.
关于javascript - http.get 解析错误,代码 : 'HPE_UNEXPECTED_CONTENT_LENGTH' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35525715/