@NonNull private SyncHttpClient getUnsafeSyncHttpClient() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException { // We initialize a default Keystore KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); // We load the KeyStore trustStore.load(null, null); // We initialize a new SSLSocketFactory MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore); // We set that all host names are allowed in the socket factory socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // We initialize the Async Client SyncHttpClient client = new SyncHttpClient(); // We set the timeout to 30 seconds client.setTimeout(TIMEOUT); // We set the SSL Factory client.setSSLSocketFactory(socketFactory); client.setEnableRedirects(true); client.setUserAgent("Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36"); return client; }
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; } }
private void init() { asyncHttpClient = new SyncHttpClient(); asyncHttpClient.setTimeout(60 * 1000); asyncHttpClient.setSSLSocketFactory(MySSLSocketFactory.getFixedSocketFactory()); asyncHttpClient.setCookieStore(new BasicCookieStore());//new PersistentCookieStore(context); addHeader("Accept", "application/json;"); addHeader("Connection", "keep-alive"); }