android应用程序中的错误:javax.net.ssl.SSLPeerUnverifiedException:没有对等证书 [英] Error in android application: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

查看:626
本文介绍了android应用程序中的错误:javax.net.ssl.SSLPeerUnverifiedException:没有对等证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,可能会寻求建议. 我的代码正常工作,但是有一天没有明显原因,也没有更改服务器上的代码,因此停止工作,并显示此错误 我已经检查了链接引用的决策,但是没有一个给出理想的结果. SSL协议中可能包含某些内容?

Good day, may ask for advice. My code is worked properly, but one day for no apparent reason and without changes to the code on the server stopped working, displaying this error I have checked the decisions referred to by links, but none of them gave the desired result. Perhaps there was something in the SSL protocol?

安全修复:javax.net.ssl.SSLPeerUnverifiedException:没有对等证书

javax.net.ssl.sslpeerunverifiedexception没有对等证书

Android ssl:javax.net.ssl. SSLPeerUnverifiedException:没有对等证书

使用基于HTTPS的HttpClient信任所有证书

class RequestTask extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... params) {

        try {

            HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

            DefaultHttpClient client = new DefaultHttpClient();

            SchemeRegistry registry = new SchemeRegistry();
            SSLSocketFactory socketFactory = SSLSocketFactory
                    .getSocketFactory();
            socketFactory
                    .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
            registry.register(new Scheme("https", socketFactory, 443));
            SingleClientConnManager mgr = new SingleClientConnManager(
                    client.getParams(), registry);
            DefaultHttpClient httpClient = new DefaultHttpClient(mgr,
                    client.getParams());

            HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            ResponseHandler<String> res = new BasicResponseHandler();

            HttpPost postMethod = new HttpPost("https://api.equalibra.net/banners.json");

            nameValuePairs.add(new BasicNameValuePair("lang", "rus"));
            postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                    HTTP.UTF_8));

            String response = "";
            try {
                response = httpClient.execute(postMethod, res);
            } catch (Exception e) {
                Log.d("my", e.toString());
            }

            JSONURL(response);

        } catch (Exception e) {
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
}

推荐答案

实际上,问题是我的Android SDK不支持SNI. 它对我有帮助:

Indeed, the problem was that my Android SDK does not support SNI . It helped me:

这篇关于android应用程序中的错误:javax.net.ssl.SSLPeerUnverifiedException:没有对等证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆