andorid HTTPS 不需要证书 VolleyEror: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not fou

1.加证书(这里不说)

2.修改代码

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
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;

/**
*
*
* Created by Administrator on 2016/2/17.
*/
public class FakeX509TrustManager implements X509TrustManager {

private static TrustManager[] trustManagers;
   private static final X509Certificate[] _AcceptedIssuers = new
           X509Certificate[] {};

@Override
   public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
       //To change body of implemented methods use File | Settings | File Templates.
   }

@Override
   public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
       //To change body of implemented methods use File | Settings | File Templates.
   }

public boolean isClientTrusted(X509Certificate[] chain) {
       return true;
   }

public boolean isServerTrusted(X509Certificate[] chain) {
       return true;
   }

@Override
   public X509Certificate[] getAcceptedIssuers() {
       return _AcceptedIssuers;
   }

public static void allowAllSSL() {
       HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

@Override
           public boolean verify(String arg0, SSLSession arg1) {
               // TODO Auto-generated method stub
               return true;
           }

});

SSLContext context = null;
       if (trustManagers == null) {
           trustManagers = new TrustManager[] { new FakeX509TrustManager() };
       }

try {
           context = SSLContext.getInstance("TLS");
           context.init(null, trustManagers, new SecureRandom());
       } catch (NoSuchAlgorithmException e) {
           e.printStackTrace();
       } catch (KeyManagementException e) {
           e.printStackTrace();
       }

HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
   }

}

在调用网络前使用

FakeX509TrustManager.allowAllSSL(); //it is dangerous!但是有的时候我们需要这样做!!       //========================StringRequest=====================================================       StringRequest httpRequest = new StringRequest(requestMethod, url, new Response.Listener<String>() {           @Override           public void onResponse(String response) { 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

时间: 2024-08-24 19:39:26

andorid HTTPS 不需要证书 VolleyEror: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not fou的相关文章

解决 Java 调用 Azure SDK 证书错误 javax.net.ssl.SSLHandshakeException

Azure 作为微软的公有云平台,提供了非常丰富的 SDK 和 API 让开发人员可以非常方便的调用的各项服务,目前除了自家的 .NET.Java.Python. nodeJS.Ruby,PHP 等语言都提供支持,详细的文档说明请参考: https://azure.microsoft.com/en-us/documentation/ 然而在使用过程中,以 Java 语言为例,在初始调用 Azure SDK/API 的时候大家会碰到类似下面的错误: [WARN] ServiceBusContrac

javax.net.ssl.SSLHandshakeException(Cas导入证书)

一.报错: javax.net.ssl.SSLHandshakeException 二.原因分析:CAS部署时,常常要涉及到HTTPS的证书发布问题.由于在实验环境中,CAS和应用服务常常是共用一台PC机,它们跑在相同的JRE环境和Tomcat服务器上,因此忽略了证书的实际用途,一旦将CAS和应用分别部署在不同的机器上时,就晕了! 这里假设如下实验环境来说明相应的部署  机器A: 部署CAS服务  机器B: 部署OA应用 机器C: 用户浏览器端 1.由机器A上生成.keystore的证书文件,证

[Android Exception 1A] -com.android.volley.NoConnectionError: java.io.InterruptedIOException

12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err: com.android.volley.NoConnectionError: java.io.InterruptedIOException 12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err: at com.android.volley.toolbox.BasicNetwork.perfor

微信证书 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

这几天在做微信退款接口,按照api写完之后,在本地测试了下没有问题,于是交给测试让他们在测试环境开测.他们说退款没有成功,感觉去查日志,发现后台报了 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty .退款证书没

Java调用https服务报错unable to find valid certification path to requested target的解决方法

我们网站要进行https改造,配置上购买的SSL证书后,浏览器访问正常,但是写了个java代码用httpcomponents调用https rest接口时报错: Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath

java连接https时禁用证书验证.

import java.io.File; import java.security.cert.CertificateException; import java.util.List; import java.util.Map; import javax.net.ssl.SSLContext; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustSelfSi

android volley框架

1 Volley发送get请求: [java] view plaincopy public void getJson() { String url = "http://"+host+":8080/web/json.jsp?username=xjs&password=123456"; mQueue.add(new JsonObjectRequest(Method.GET, url, null, new Listener<JSONObject>() 

转载-解决使用httpClient 4.3.x登陆 https时的证书报错问题

今天在使用httpClient4.3.6模拟登陆https网站的时候出现了证书报错的问题,这是在开源中国社区里找到的可行的答案(原文链接:http://www.oschina.net/question/194048_135225?sort=time) 大概逻辑是自己实现了信任所有证书 import javax.net.ssl.SSLContext; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apa

【http转https】其之二:申请Let&#39;s Encrypt颁发SSL证书

[http转https]其之二:申请Let's Encrypt颁发SSL证书 文:铁乐猫2017年1月12日 申请Let's Encrypt颁发SSL证书 由 ISRG(Internet Security Research Group,互联网安全研究小组)提供服务, ISRG 来自于美国加利福尼亚州的一个公益组织.Let's Encrypt 得到了 Mozilla.Cisco.Akamai.Electronic Frontier Foundation 和 Chrome 等众多公司和机构的支持,发