SSL握手中止:ssl = 0x55ad47e080:系统调用期间的I / O错误,对等方重置连接
Posted
技术标签:
【中文标题】SSL握手中止:ssl = 0x55ad47e080:系统调用期间的I / O错误,对等方重置连接【英文标题】:SSL handshake aborted: ssl=0x55ad47e080: I/O error during system call, Connection reset by peer 【发布时间】:2019-11-23 21:27:48 【问题描述】:我使用Retrofit 库向服务器的 API 发送请求。我的服务器 URL 使用 HTTPS 协议。有时我会在几分钟后重新启动应用程序并修复它时收到此错误。
SSL 握手中止:ssl=0x55ad47e080:系统调用期间 I/O 错误,对等方重置连接
我在 *** 中阅读了所有答案并设置了 TLSSocketFactory.java 但问题没有解决。
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class TLSSocketFactory extends SSLSocketFactory
private final SSLSocketFactory delegate;
private TrustManager[] trustManagers;
TLSSocketFactory() throws KeyStoreException, KeyManagementException, NoSuchAlgorithmException
generateTrustManagers();
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, null);
delegate = context.getSocketFactory();
private void generateTrustManagers() throws KeyStoreException, NoSuchAlgorithmException
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager))
throw new IllegalStateException("Unexpected default trust managers:"
+ Arrays.toString(trustManagers));
this.trustManagers = trustManagers;
@Override
public String[] getDefaultCipherSuites()
return delegate.getDefaultCipherSuites();
@Override
public String[] getSupportedCipherSuites()
return delegate.getSupportedCipherSuites();
@Override
public Socket createSocket() throws IOException
return enableTLSOnSocket(delegate.createSocket());
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException
return enableTLSOnSocket(delegate.createSocket(s, host, port, autoClose));
@Override
public Socket createSocket(String host, int port) throws IOException
return enableTLSOnSocket(delegate.createSocket(host, port));
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException
return enableTLSOnSocket(delegate.createSocket(host, port, localHost, localPort));
@Override
public Socket createSocket(InetAddress host, int port) throws IOException
return enableTLSOnSocket(delegate.createSocket(host, port));
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException
return enableTLSOnSocket(delegate.createSocket(address, port, localAddress, localPort));
private Socket enableTLSOnSocket(Socket socket)
if (socket instanceof SSLSocket)
((SSLSocket) socket).setEnabledProtocols(new String[]"TLSv1.1", "TLSv1.2");
return socket;
X509TrustManager getTrustManager()
return (X509TrustManager) trustManagers[0];
为什么会出现这个错误,我该如何解决?
【问题讨论】:
你试过这个***.com/a/42471738/6549598 吗? 不适合我! 【参考方案1】:试试,
setKeepAlive(true)
setSoKeepalive(HttpParams params, enableKeepalive="true")
参考这个, Connection reset by peer exception
【讨论】:
你能解释一下吗?我不明白你实现它的答案。 client = new Socket(hostName, port); client.setKeepAlive(true);以上是关于SSL握手中止:ssl = 0x55ad47e080:系统调用期间的I / O错误,对等方重置连接的主要内容,如果未能解决你的问题,请参考以下文章
javax.net.ssl.SSLException:SSL 握手中止连接由对等方重置,同时调用 web 服务 Android
IOException:javax.net.ssl.SSLHandshakeException:SSL 握手中止:ssl=0xafdb8e00:系统调用期间的 I/O 错误,对等方重置连接
STM32Cube_FW_F7 客户端 mbedTLS SSL 握手失败并显示 FATAL_ALERT
com.android.volley.NoConnectionError:javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolEx