异常:
javax.NET.ssl.SSLException:hostname in certificate didn’t match:<..*.com> != <.**.com>
解决:
publicstaticSchemeRegistrygetSchemeRegistry(){
try{
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null,null);
SSLSocketFactory sf =newMySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParamsparams=newBasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params,10000);
HttpConnectionParams.setSoTimeout(params,10000);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry =newSchemeRegistry();
registry.register(newScheme("http", PlainSocketFactory.getSocketFactory(),80));
registry.register(newScheme("https", sf,443));
returnregistry;
}catch(Exception e) {
return null; } }
asynchttpclient 初始化的时候 new AsyncHttpClient(getSchemeRegistry()); 传入这个方法返回值就可以了。