SSLPeerUnverifiedException OkHttp?

后端 未结 3 1726

I\'m trying to use OkHttp library to send post request to API with some url parameters. Following this blog post I have this code so far:

           


        
3条回答
  •  北海茫月
    2021-01-03 05:05

    Check SSLSession hostname and your connection host name...

    OkHttpClient client = new OkHttpClient();
    client.setHostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    if (!urlHostName.equalsIgnoreCase(session.getPeerHost())) {
                        System.out.println("Warning: URL host '" + urlHostName
                                + "' is different to SSLSession host '"
                                + session.getPeerHost() + "'.");
                    }
                    return true;
                }
            });
    

提交回复
热议问题