如何解决javax.net.ssl.SSLPeerUnverifiedException:主机名.com未验证: [英] how to solve javax.net.ssl.SSLPeerUnverifiedException: Hostname .com not verified:

查看:328
本文介绍了如何解决javax.net.ssl.SSLPeerUnverifiedException:主机名.com未验证:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误Hostname domain.com not verified:不是"javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated"在连接到其他主机之前我已经能够,在此主机中我遇到问题,如何解决

I am having the following error Hostname domain.com not verified: Not "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated" I was able before to connect to different host, in this host I am facing problems , how to fix it

 javax.net.ssl.SSLPeerUnverifiedException: Hostname domain.com not verified:
    certificate: sha1//WQM9QbrKs6DCFa9qN/EIw1ywBw=
    DN: CN=*.ipage.com,OU=Domain Control Validated - RapidSSL(R),OU=See www.rapidssl.com/resources/cps (c)14,OU=GT29505539
    subjectAltNames: [*.ipage.com, ipage.com]
            at com.squareup.okhttp.Connection.connectTls(Connection.java:244)
            at com.squareup.okhttp.Connection.connectSocket(Connection.java:199)
            at com.squareup.okhttp.Connection.connect(Connection.java:172)
            at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
            at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
            at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
            at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
            at com.squareup.okhttp.Call.getResponse(Call.java:267)

这是我的代码

  try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.accumulate("name", name);
                    jsonObject.accumulate("password", pass);
                    jsonObject.accumulate("email", emails);
                    json = jsonObject.toString();
                    Log.e("MYAPP", "getjson");

                } catch (JSONException e) {
                    Log.e("MYAPP", "unexpected JSON exception", e);
                }
                try{
                    RequestBody formBody = new FormEncodingBuilder()
                            .add("name", name)
                            .build();
                    Request request = new Request.Builder()
                            .url("https://justedhak.com/Files/users.php")
                            .post(formBody)
                            .build();

推荐答案

更新

因为javax.net.ssl.SSLPeerUnverifiedException: Hostname justedhak.com not verifiedDN: CN=*.ipage.com...subjectAltNames: [*.ipage.com, ipage.com]

因此,您可以将以下示例代码中的setHostnameVerifier替换为以下内容(因为不建议使用return true):

As a result, you can replace the setHostnameVerifier at my below sample code (because return true is not recommended) by the following:

client.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                //return true;
                HostnameVerifier hv =
                        HttpsURLConnection.getDefaultHostnameVerifier();
                return hv.verify("ipage.com", session);
            }
        });

您还将获得成功的结果,如以下屏幕截图所示.

You will get the success result as the below screenshot too.

如果仅出于学习目的或开发环境而使用该主机的HTTPS,则可以参考以下方式,当然,您可以更改您的POST提出的GET请求:

If you want to work with that host's HTTPS only for your learning purpose or developing environment, you can refer the following way, of course you can change my GET request by your POST one:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = (TextView) findViewById(R.id.textView);
        mHandler = new Handler(Looper.getMainLooper());
        OkHttpClient client = new OkHttpClient();
        client.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        Request request = new Request.Builder()
                .url("https://justedhak.com/Files/users.php")
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                // do something...
                Log.e(LOG_TAG, e.toString());
            }

            @Override
            public void onResponse(Response response) throws IOException {
                // do something...
                Log.i(LOG_TAG, response.body().string());
            }
        });
    }

这是屏幕截图

您还可以阅读以下问题的更多信息:

You can also read more at the following question:

OkHttp信任证书

这篇关于如何解决javax.net.ssl.SSLPeerUnverifiedException:主机名.com未验证:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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