这个问题已经在这里有一个答案:
- java.net.SocketException异常:软件导致连接中止:recv的失败,与java.net.SocketException异常:连接复位[复制] 3个回答
我想以编程方式(JAVA)打开指向网络上的调制解调器的URL。 我连接到网络,并可以ping通设备,以及在浏览器中获取URL。 然而,编程,试图打开连接时,我得到了下面的堆栈跟踪。
java.net.SocketException: Software caused connection abort: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
此外,URL使用HTTPS协议。
这里是我的代码:
try {
URL jipmURL = new URL("https://xxx.xxx.xxx.xxx/login.cgi");
URLConnection urlConnection = jipmURL.openConnection();
InputStreamReader streamReader = new InputStreamReader(
jipmURLConnection.getInputStream());
BufferedReader in = new BufferedReader(streamReader);
StringBuffer stringBuffer = new StringBuffer();
String inputLine;
while ((inputLine = in.readLine()) != null) {
stringBuffer.append(inputLine);
}
System.out.println("Results: " + stringBuffer);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
任何帮助,将不胜感激,
史蒂夫