[英]Why am I getting “Error socket hang up” response?
I tried to scrape a website.我试图抓取一个网站。 And I am using the library https://github.com/request/request , but I get this error:
我正在使用库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
What is wrong here?这里有什么问题? I also tried to re-install the package, but I get same error... help is appreciated.
我也尝试重新安装该软件包,但我遇到了同样的错误......感谢帮助。
I recently got this socket hang up
problem.我最近遇到了这个
socket hang up
问题。 I researched for a few days until I found a solution that worked for me.我研究了几天,直到找到适合我的解决方案。 So, maybe this can help.
所以,也许这会有所帮助。
It worked for me to add the http(s)Agent
property with keepAlive: true
in creating the http client.在创建 http 客户端时使用
keepAlive: true
添加http(s)Agent
属性对我keepAlive: true
。 Here's an example of what it might look like:下面是它可能是什么样子的示例:
const http = require('http')
http.request({
method: 'GET',
agent: http.Agent({keepAlive:true}),
host: 'www.google.com',
})
This property is responsible for managing the sockets for client-side http connections.此属性负责管理客户端 http 连接的套接字。 The justification for using this property can be found here .
可以在此处找到使用此属性的理由。
I also found an answer on the stackoverflow that also covers the subject, here .我还在 stackoverflow 上找到了一个答案,该答案也涵盖了该主题, here 。
So, I hope this helps.所以,我希望这会有所帮助。
check the bellow link for the source code检查源代码的波纹管链接
https://github.com/joyent/node/blob/ba048e72b02e17f0c73e0dcb7d37e76a03327c5a/lib/_http_client.js#L164 https://github.com/joyent/node/blob/ba048e72b02e17f0c73e0dcb7d37e76a03327c5a/lib/_http_client.js#L164
or check the following question或检查以下问题
NodeJS - What does "socket hang up" actually mean? NodeJS - “套接字挂断”实际上是什么意思?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.