Use the simple DefaultHttpClient or the keystore created with the BouncyCastle bundled

The server to which the application is connected had a temporary certificate or something like that. I only care about the Android app, and to make calls to the https web services, the app used an insecure interface implementation X509TrustManager. The server certificate has now been fixed and has a final certificate.

The following code works:

HttpClient mHttpClient = null;
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 30000);
DefaultHttpClient client = new DefaultHttpClient(httpParameters);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https",  SSLSocketFactory.getSocketFactory(), 443));
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
mHttpClient = new DefaultHttpClient(mgr, client.getParams());
final HttpParams params = mHttpClient.getParams();

HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);

Basically, using this mHttpClientwhen making web service calls does not cause any errors or complaints and works as expected. However, I have seen implementations like this that have a safer approach.

: DefaultHttpClient , , , ? , , ?

+4

Source: https://habr.com/ru/post/1659495/


All Articles