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
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

* 证书过期不要慌…
配置容器为http请求,搞定。
* 如果postman请求遇到一下情况
Could not get any response

不要慌。。。。
解决:
A. 打开postman —> File —> Settings

B. 关闭图片红框里的SSL…选项为OFF
C. 大功告成。。。。
3. java请求…直接贴代码了。
/** * 采用绕过验证的方式处理https请求 * @param url * @param json * @return */ public static
String doGet(String url, JSONObject json) { String body = ""; SSLContext
sslcontext = null; try { //设置协议http和https对应的处理socket链接工厂的对象 sslcontext =
createIgnoreVerifySSL(); Registry<ConnectionSocketFactory>
socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new
SSLConnectionSocketFactory(sslcontext)) .build();
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager); //创建自定义的httpclient对象
CloseableHttpClient client =
HttpClients.custom().setConnectionManager(connManager).build();
//处理请求参数拼接(参数为json) 如:?name = ""&pwd = "" String param =
changeJsonToArguments(json); String urlNameString = url + param; //创建get方式请求对象
HttpGet get = new HttpGet(urlNameString); //指定报文头Content-type、User-Agent
//get.setHeader("Content-type", "application/x-www-form-urlencoded");
get.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:6.0.2)
Gecko/20100101 Firefox/6.0.2"); //执行请求操作,并拿到结果(同步阻塞) CloseableHttpResponse
response = client.execute(get); //获取结果实体 HttpEntity entity =
response.getEntity(); if (entity != null) { //按指定编码转换结果实体为String类型 body =
EntityUtils.toString(entity, "UTF-8"); } EntityUtils.consume(entity); //释放链接
response.close(); } catch (ClientProtocolException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException
e) { e.printStackTrace(); } catch (KeyManagementException e) {
e.printStackTrace(); }finally{ } return body; } public static SSLContext
createIgnoreVerifySSL() throws NoSuchAlgorithmException, KeyManagementException
{ SSLContext sc = SSLContext.getInstance("SSLv3"); //
实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法 X509TrustManager trustManager = new
X509TrustManager() { @Override public void checkClientTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String
paramString) { } @Override public void checkServerTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String
paramString) { } @Override public java.security.cert.X509Certificate[]
getAcceptedIssuers() { return null; } }; sc.init(null, new TrustManager[] {
trustManager }, null); return sc; }
有帮助请留言…替你们采坑0.0

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信