我正在尝试对URL执行get请求。当我在网络浏览器中点击URL时,通常需要大约2分钟才能加载。
当我尝试从Java调用它时 - 我收到SocketException连接重置错误。
Error: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
我正在尝试执行getResponseCode,当我尝试从流中读取时,我遇到了同样的错误。
如何解决此问题?
我尝试将连接超时和读取超时设置为5分钟。他们都没有工作。
编辑:[添加代码]以下是代码,我在执行getResponseCode并使用getInputStream读取流时遇到同样的错误。
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(TIMEOUT); //5 mins
connection.setReadTimeout(TIMEOUT); //5 mins
connection.getResponseCode();
IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
我不认为这是服务器问题,因为我能够使用其他通常在浏览器中加载15-30秒的params。只有这个特定的请求失败了。 (此请求需要2分钟才能在浏览器中加载)