Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
间歇性PeerRunVerifiedException:Android客户端没有对等证书_Android_Apache_Ssl_Https_Ssl Certificate - Fatal编程技术网

间歇性PeerRunVerifiedException:Android客户端没有对等证书

间歇性PeerRunVerifiedException:Android客户端没有对等证书,android,apache,ssl,https,ssl-certificate,Android,Apache,Ssl,Https,Ssl Certificate,我正在努力实现Android↔ Apache使用HTTPS进行通信,但我得到以下错误。我间歇性地遇到这个问题,大约有30%的时间 我在网上搜索,但任何答案都帮了我 以下是我的Android代码: http\u post=新的HttpPost(Utils.IP\u地址); http_post_data=new ArrayList(); http_post_data.add(新的BasicNameValuePair(“regId”,regId)); http_post_data.add(新的Basi

我正在努力实现Android↔ Apache使用HTTPS进行通信,但我得到以下错误。我间歇性地遇到这个问题,大约有30%的时间

我在网上搜索,但任何答案都帮了我

以下是我的Android代码:

http\u post=新的HttpPost(Utils.IP\u地址);
http_post_data=new ArrayList();
http_post_data.add(新的BasicNameValuePair(“regId”,regId));
http_post_data.add(新的BasicNameValuePair(“email”,globals.userInfo.mail));
http_post_data.add(新的BasicNameValuePair(“pass”,globals.userInfo.pass));
setEntity(新的UrlEncodedFormEntity(http_post_数据));
HttpParams httpParameters=新的BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,Utils.TIMEOUT\u连接);
HttpConnectionParams.setSoTimeout(httpParameters,Utils.TIMEOUT_套接字);
http_client=新的DefaultHttpClient(httpParameters);
response=http\u client.execute(http\u post);
String ResponseBy=EntityUtils.toString(response.getEntity(),globalSingleton.applicationCharset);

我有一张GoDaddy证书。那么,我需要在服务器或android代码中更改什么才能修复此问题呢?

我可以通过重新启动仿真器或创建新的仿真器,并在新的仿真器中运行项目来解决此问题。

替换套接字中的x509TrustManager。像这样包装您的客户机:

public static org.apache.http.client.HttpClient wrapClient(org.apache.http.client.HttpClient base) {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager tm = new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
                public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
                public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
            };
            ctx.init(null, new TrustManager[] { tm }, null);
            SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("https", 443, ssf));
            ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(registry);
            return new DefaultHttpClient(mgr, base.getParams());
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

请参考此@Fernando-您需要能够复制问题以解决问题。对于故障排除,请使用openssl s_客户端-连接主机:port-tls1-servername主机。此外,您需要发布详细信息,如URL或服务器名称,以便我们可以尝试复制它。拒绝向我们提供详细信息没有任何意义,因为该服务器位于web上,可供坏人使用。@Fernando-该网站在哪里托管,负载平衡吗?另请参见
SSLSocketFactoryEx
,以确保从Android获得配置良好的SSL/TLS套接字。你可以在
public static org.apache.http.client.HttpClient wrapClient(org.apache.http.client.HttpClient base) {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager tm = new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
                public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
                public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
            };
            ctx.init(null, new TrustManager[] { tm }, null);
            SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("https", 443, ssf));
            ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(registry);
            return new DefaultHttpClient(mgr, base.getParams());
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }