解决asynchttpclient https请求报错hostname in certificate didn't match:

来源:互联网 发布:吃土(网络词汇) 编辑:程序博客网 时间:2024/06/07 23:01

错误:
javax.NET.ssl.SSLException:hostname in certificate didn’t match:<..*.com> != <.**.com>

解决办法:

public static SchemeRegistry getSchemeRegistry() {        try {            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());            trustStore.load(null, null);            SSLSocketFactory sf = new MySSLSocketFactory(trustStore);            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);            HttpParams params = new BasicHttpParams();            HttpConnectionParams.setConnectionTimeout(params, 10000);            HttpConnectionParams.setSoTimeout(params, 10000);            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);            SchemeRegistry registry = new SchemeRegistry();            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));            registry.register(new Scheme("https", sf, 443));            return registry;        } catch (Exception e) {            return null;        }    }

asynchttpclient 初始化的时候 new AsyncHttpClient(getSchemeRegistry()); 传入这个方法返回值就可以了。

阅读全文
0 0