首页 > 解决方案 > 在 Heroku 中部署爬虫并获取 java.net.SocketTimeoutException: Read timed out

问题描述

我编写了一个快速应用程序,它转到一个 URL 并检查一些信息,它在我的本地工作得很好,但是当我部署到 Heroku 时,它会引发以下异常:

PS:我使用 HTMLUnit

021-02-15T04:47:07.740845+00:00 app[web.1]: java.net.SocketTimeoutException: Read timed out
2021-02-15T04:47:07.741156+00:00 app[web.1]:    at java.net.SocketInputStream.socketRead0(Native Method)
2021-02-15T04:47:07.741208+00:00 app[web.1]:    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
2021-02-15T04:47:07.741246+00:00 app[web.1]:    at java.net.SocketInputStream.read(SocketInputStream.java:171)
2021-02-15T04:47:07.741285+00:00 app[web.1]:    at java.net.SocketInputStream.read(SocketInputStream.java:141)
2021-02-15T04:47:07.741326+00:00 app[web.1]:    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
2021-02-15T04:47:07.741398+00:00 app[web.1]:    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
2021-02-15T04:47:07.741458+00:00 app[web.1]:    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
2021-02-15T04:47:07.741522+00:00 app[web.1]:    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
2021-02-15T04:47:07.741591+00:00 app[web.1]:    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
2021-02-15T04:47:07.741650+00:00 app[web.1]:    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
2021-02-15T04:47:07.741717+00:00 app[web.1]:    at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
2021-02-15T04:47:07.741758+00:00 app[web.1]:    at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157)
2021-02-15T04:47:07.741802+00:00 app[web.1]:    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
2021-02-15T04:47:07.741845+00:00 app[web.1]:    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
2021-02-15T04:47:07.741885+00:00 app[web.1]:    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
2021-02-15T04:47:07.741914+00:00 app[web.1]:    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
2021-02-15T04:47:07.741949+00:00 app[web.1]:    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
2021-02-15T04:47:07.741993+00:00 app[web.1]:    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
2021-02-15T04:47:07.742026+00:00 app[web.1]:    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
2021-02-15T04:47:07.742064+00:00 app[web.1]:    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
2021-02-15T04:47:07.742107+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:192)
2021-02-15T04:47:07.742149+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1545)
2021-02-15T04:47:07.742190+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1468)
2021-02-15T04:47:07.742228+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:462)
2021-02-15T04:47:07.742266+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
2021-02-15T04:47:07.742303+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:539)
2021-02-15T04:47:07.742358+00:00 app[web.1]:    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:520)

标签: javaspringherokuhtmlunit

解决方案


推荐阅读