亲切的 Attn 版主:在将此查询标记为重复之前,请注意我已经检查了这些问题...
- java.net.SocketException:连接重置
- 是什么导致我的 java.net.SocketException:连接重置?
- 收到错误“java.net.SocketException:连接重置”
...并且无法解决问题。另外我相信上下文和错误与那些不同,因此在这里寻求帮助。
上下文:从 NSEIndia 网站下载 csv 文件到本地文件夹(注意:我能够从其他随机网站下载 CSV 文件)。
问题:返回错误 - javax.net.ssl.SSLException:连接重置(下面粘贴了完整错误)
观察:我很困惑,因为我昨天遇到了同样的问题,但经过几次重试,它成功了。我没有更改代码或设置。
问题:我能做些什么来确保在这个特定网站上看不到这个错误?
代码:
// Using FileUtils from -> import org.apache.commons.io.FileUtils;
try {
FileUtils.copyURLToFile(new URL("https://www.nseindia.com/content/fo/fo_mktlots.csv"),new File("D:\\Download\\t1.csv"));
} catch (IOException e) {
e.printStackTrace();
}
错误:
javax.net.ssl.SSLException: Connection reset
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:324)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:267)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:262)
at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1652)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1038)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:245)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:285)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:344)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:746)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:717)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1610)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
at java.base/java.net.URL.openStream(URL.java:1162)
at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1456)
at main.Test.dummy3(Test.java:327)
at main.Test.main(Test.java:59)
Suppressed: java.net.SocketException: Connection reset by peer
at java.base/sun.nio.ch.NioSocketImpl.implWrite(NioSocketImpl.java:421)
at java.base/sun.nio.ch.NioSocketImpl.write(NioSocketImpl.java:441)
at java.base/sun.nio.ch.NioSocketImpl$2.write(NioSocketImpl.java:825)
at java.base/java.net.Socket$SocketOutputStream.write(Socket.java:1007)
at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:82)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:355)
... 17 more
Caused by: java.net.SocketException: Connection reset
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:324)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:351)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:802)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:937)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:450)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:68)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1409)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1022)
... 13 more