1.最近發現java發送https請求時,會報一個證書異常現象(我的的是在本地windows系統上能夠正常訪問https路徑,但在linux系統上不能訪問,後來發現是由於本地%JAVA_HOME%/jre/lib/security和linux上的cacerts證書版本不一致,linux上的是2015-4-16的,比較落後了) -->報錯所有信息以下 異常堆棧信息:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target sun.security.ssl.Alerts.getSSLException(Alerts.java:192) sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937) sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1478) sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212) sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) sun.security.ssl.Handshaker.process_record(Handshaker.java:914) sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1050) sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363) sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391) sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375) org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395) org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:354) org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)java
2.根本緣由: Java在請求某些不受信任的https網站時會報:PKIX path building failedlinux
3.解決辦法: 1)、導入證書到本地證書庫apache
2)、信任全部SSL證書windows
4.網上推薦使用 3.2,我的嘗試了一下不行,這裏講解我的的解決方式服務器
將最新的cacerts文件,替換到linux服務器上\jre\lib\security\目錄下,替換老版本的證書ide