错误套接字挂断

时间:2015-04-21 08:38:02

标签: node.js express request npm

我试过刮网站..我正在使用库https://github.com/request/request, 但是我得到了这个错误

Error: socket hang up at createHangUpError (http.js:1476:15) at Socket.socketOnEnd (http.js:1572:23) at Socket.g (events.js:180:16) at Socket.emit (events.js:117:20) at _stream_readable.js:943:16 at process._tickDomainCallback (node.js:463:13) +0ms

什么错了?我也试过重新安装包,但我得到同样的错误..

请帮助...

2 个答案:

答案 0 :(得分:2)

我最近遇到了这个 socket hang up 问题。我研究了几天,直到找到适合我的解决方案。所以,也许这会有所帮助。

在创建 http 客户端时添加带有 http(s)AgentkeepAlive: true 属性对我很有用。下面是它的外观示例:

const http = require('http')
http.request({
        method: 'GET',
        agent: http.Agent({keepAlive:true}),
        host: 'www.google.com',
    })

该属性负责管理客户端 http 连接的套接字。可以在 here 中找到使用此属性的理由。

我还在 stackoverflow 上找到了一个答案,该答案也涵盖了该主题,here

所以,我希望这会有所帮助。

答案 1 :(得分:0)

相关问题