javascript - http.get 解析错误,代码 : 'HPE_UNEXPECTED_CONTENT_LENGTH'

标签 javascript node.js

我有一个简单的 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-LengthTransfer-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/

相关文章:

javascript - "new Dog"或 "new Dog()"

javascript - 为什么这个 window.onload 没有触发我的函数?

node.js - 使用 react 组件加载特定 DIV 而无需重新加载整个页面

node.js - Socket.IO 启动客户端到第三方服务器的连接

node.js - 使用 Node js将数据写入excel文件

javascript - 我如何让用户能够发布并将其保留在网站上?

Angular 模板中的 Javascript 广告

javascript - Twitter-bootstrap 导航栏下拉菜单表现异常(不在移动设备上工作,不在桌面上显示)

node.js - Openshift NodeJS + MongoDB 应用程序突然停止

node.js - 无法在 Node.js 中将 Gmail 联系人与 passport-google-oauth 同步