HTTPS请求异常
0
今天使用自己写的HTTP工具发现访问https://www.acgist.com
时,提示:
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
之前是没有问题的,怎么突然就提示这个错误,原来前几天我升级了一下Nginx的HTTPS协议版本,去掉了旧的SSL,所以以前的代码也要修改:
//SSLContext context = SSLContext.getInstance("SSL"); // 旧版本
SSLContext context = SSLContext.getInstance("TLSv1.2"); // 升级版本
如果是使用Apache的HTTPClient工具:
private static SSLConnectionSocketFactory createSSLConnSocketFactory() {
SSLContext sslContext = null;
SSLConnectionSocketFactory sslFactory = null;
try {
sslContext = org.apache.http.ssl.SSLContextBuilder.create().loadTrustMaterial(null, new TrustStrategy() {
// 支持TLS
// sslContext = org.apache.http.ssl.SSLContextBuilder.create().useProtocol("TLSv1.2").loadTrustMaterial(null, new TrustStrategy() {
// 信任所有证书
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
} catch (Exception e) {
logger.error("创建SSL工程异常", e);
}
sslFactory = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
// 支持TLS
// sslFactory = new SSLConnectionSocketFactory(sslContext, new String[] {"TLSv1.2"}, null, new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true; // 不检查证书和域名是否匹配
}
});
return sslFactory;
}
同样可能还有一个问题,就是SVN提交更改时提示502
错误:
RA layer request failed
svn: Commit failed (details follow):
svn: COPY request on '/!svn/bc/1059/projects/trunk/acgist_www/src/main/java/com/acgist/bean/dto/URLRepeat.java' failed: 502 Bad Gateway
这个需要修改Apache配置:
#下面的模块默认已经加载
LoadModule headers_module modules/mod_headers.so
#修改httpd.conf,在最后添加
<IfModule headers_module>
RequestHeader edit Destination ^https: http: early
</IfModule>
Done