使用Java访问https接口javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
2017-05-17 13:49
751 查看
jdk1.6,证书:SHA256+TLSv1.2
使用Java访问https://**************** 接口 控制台提示握手失败错误;javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
解决办法:
1.jdk版本问题,换用jdk1.7;
2.如不能更换jdk版本,引入 bcprov-jdk15on-157.jar 此jar包对jdk1.5-1.8都可支持;
使用Java访问https://**************** 接口 控制台提示握手失败错误;javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
解决办法:
1.jdk版本问题,换用jdk1.7;
2.如不能更换jdk版本,引入 bcprov-jdk15on-157.jar 此jar包对jdk1.5-1.8都可支持;
public static String httpsRequsetForTLSv12(String host, String url) throws Exception { java.security.SecureRandom secureRandom = new java.security.SecureRandom(); Socket socket = new Socket(java.net.InetAddress.getByName(host), 443); TlsClientProtocol protocol = new TlsClientProtocol(socket.getInputStream(), socket.getOutputStream(),secureRandom); DefaultTlsClient client = new DefaultTlsClient() { public TlsAuthentication getAuthentication() throws IOException { TlsAuthentication auth = new TlsAuthentication() { public void notifyServerCertificate(org.bouncycastle.crypto.tls.Certificate serverCertificate) throws IOException { } public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) throws IOException { return null; } }; return auth; } }; protocol.connect(client); java.io.OutputStream output = protocol.getOutputStream(); output.write(("GET "+url+" HTTP/1.1\r\n").getBytes("UTF-8")); output.write(("Host: "+host+"\r\n").getBytes("UTF-8")); output.write("Connection: close\r\n".getBytes("UTF-8")); output.write("\r\n".getBytes("UTF-8")); output.flush(); java.io.InputStream input = protocol.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8")); String line; String result = null; while ((line = reader.readLine()) != null) { result = line; //System.out.println(line); } return result; }
相关文章推荐
- 访问https,抛出的异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- 处理Https 异常记录 javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- SSL/TLS的Handshake过程与javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure异常
- 转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- SSL/TLS的Handshake过程与javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure异常
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- SSL/TLS的Handshake过程与javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure异常
- eclipse javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
- android ksoap2 访问https javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorExce
- ios信息推送 异常 javax.net.ssl.SSLHandshakeException: Received fatal alert: handshak
- SSLHandshakeException: Received fatal alert: handshake_failure
- 调用https接口抛出javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
- 使用https出错javax.net.ssl.SSLHandshakeException: Handshake failed
- android 访问https 证书问题 报错javax.net.ssl.SSLHandshakeException