ValidatorException/SSLHandshakeException
来源:互联网 发布:苹果cms制作解析接口 编辑:程序博客网 时间:2024/06/15 01:26
来源:http://blog.csdn.net/sinat_20245997/article/details/50505207
报错: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
网上找了好多例子,贴上代码
import Java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.Net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class HttpsUtil {
private static class TrustAnyTrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
}
private static class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
/**
* post方式请求服务器(https协议)
*
* @param url
* 请求地址
* @param content
* 参数
* @param charset
* 编码
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws IOException
*/
public static byte[] post(String url, String content, String charset)
throws NoSuchAlgorithmException, KeyManagementException,
IOException {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() },
new java.security.SecureRandom());
URL console = new URL(url);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
conn.setDoOutput(true);
conn.connect();
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(content.getBytes(charset));
// 刷新、关闭
out.flush();
out.close();
InputStream is = conn.getInputStream();
if (is != null) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
is.close();
return outStream.toByteArray();
}
return null;
}
}
- ValidatorException/SSLHandshakeException
- SSLHandshakeException: *.ValidatorException: PKIX path building failed: *.SunCertPathBuilderExceptio
- 报错javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building f
- Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
- javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException: PKIX path building失败
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building f
- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building
- 解决 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path buildin
- 爬数据出现错误javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
- SSLHandshakeException
- SSLHandshakeException
- Exception:SSLHandshakeException
- SSLHandshakeException/SSLPeerUnverifiedException
- sun.security.validator.ValidatorException
- javax.net.ssl.SSLHandshakeException
- javax.net.ssl.SSLHandshakeException
- javax.net.ssl.SSLHandshakeException
- json串的解析与制造
- java子窗体关闭时防止主窗体退出
- java比较器的实现
- SPI、I2C、UART串行总线
- Tinker接入及源码分析(一)
- ValidatorException/SSLHandshakeException
- eclipse中的快捷键
- 统计降尺度与动力学降尺度
- android 设置TextView的文本 上下左右 图标
- 数据结构:散列1(分离链接法)
- OAuth2.0协议
- kafka(1)- kafka入门
- Android 系列 6.23让他们看打星标:使用RatingBar
- Linux for Matlab中文注释乱码(亲测有效)