javascript - NodeJS 请求模块 - http.IncomingMessage 上的正文?

标签 javascript node.js node-request

我正在查看 Node 的 request模块,文档说回调接受三个参数 - errorresponse (http.IncomingMessage) 和 body

在发出请求时,我发现 body 也可以作为 response 对象的属性使用。
那可靠吗?我可以省略回调中的最后一个参数并使用 response.body 代替吗?

最佳答案

response.body 并不总是与 body 参数相同。如果请求对响应进行任何处理(例如解压缩),则 body 参数将是该处理的结果,但 response.body 可能不会反射(reflect)该处理。您应该使用 response 参数。以下是文档中的一个示例:

For backwards-compatibility, response compression is not supported by default. To accept gzip-compressed responses, set the gzip option to true. Note that the body data passed through request is automatically decompressed while the response object is unmodified and will contain compressed data if the server sent a compressed response.

关于javascript - NodeJS 请求模块 - http.IncomingMessage 上的正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36948231/

相关文章:

javascript - electron-packager 不设置图标

javascript - IE 对哈希更改发出额外的 GET 请求

javascript - 是否可以将 domparser 元素更改为字符串?

node.js - 从 Laravel Forge-Setup 中的 Laravel 应用程序执行 "npm"

javascript - 如何将全局/公共(public)变量添加到 grunt-contrib-uglify 输出

node.js - 触发 GET 请求并获取 Node Stream

node.js - 来自 Graph 的 base64 转换照片显示为损坏的图像

javascript - Google 图表 - 工具提示中的图表

node.js - MongoDB 保存用户时电子邮件和密码无效

node.js - 类型错误 : Request path contains unescaped characters NodeJS + Dynamics