如何处理httpclient的ssl错误
来源:互联网 发布:图解电影的软件 编辑:程序博客网 时间:2024/06/05 08:16
今天使用httpclient 4.5,爬取https网站时报错:
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 at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1627) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:204) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:198) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:994) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:142) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:533) at sun.security.ssl.Handshaker.process_record(Handshaker.java:471) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:904) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1132) at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:643) at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:78) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828) at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at simpleapachehttp.Main.main(Main.java:41)Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:302) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:205) at sun.security.validator.Validator.validate(Validator.java:235) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:147) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:230) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:270) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:973) ... 17 moreCaused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:191) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:255) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:297) ... 23 more
网上搜索时,各种答案,最后采用下列方法解决:
org.apache.http.ssl.SSLContextBuilder context_b = SSLContextBuilder.create(); context_b.loadTrustMaterial(new org.apache.http.conn.ssl.TrustSelfSignedStrategy()); SSLContext ssl_context = context_b.build(); org.apache.http.conn.ssl.SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(ssl_context, new org.apache.http.conn.ssl.DefaultHostnameVerifier()); HttpClientBuilder builder = HttpClients.custom() .setSSLSocketFactory(sslSocketFactory); httpclient = builder.build();
阅读全文
0 0
- 如何处理httpclient的ssl错误
- httpClient 处理SSL问题
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法 (zt)
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法 .
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- 关于httpclient的一点错误处理
- HttpClient如何访问需要提交客户端证书的SSL服务
- httpclient向HTTPS发送数据建立SSL连接时的错误
- httpclient ssl
- CAS SSL证书错误处理
- 如何使用HttpClient下载网络资源(包括下载ssl认证的资源)
- 如何使用HttpClient下载网络资源(包括下载ssl认证的资源)
- ssl解释以及学习数据库传输中出现SSL错误的处理方法
- 如何分析Java SSL错误
- nginx学习
- POJ
- JavaWeb文件下载
- cocos2dx 植物大战僵尸 15 豌豆射手的实现
- Intellij-IDEA(2017)破解
- 如何处理httpclient的ssl错误
- 3 sum
- 第1篇-JAVA开篇
- 使用IDEA创建GUI Form项目并构建
- Ubutnu 编译内核基本步骤
- 排序算法之冒泡排序
- vs2015搭建cocos2dx遇到的问题
- jsoup例子
- jquery的zTree