Created
July 24, 2015 12:57
-
-
Save ricston-git/0e7955a3b80ec58580fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomHttpClient extends DefaultHttpClient | |
{ | |
final Context context; | |
public CustomHttpClient(Context context) | |
{ | |
this.context = context; | |
} | |
@Override | |
protected ClientConnectionManager createClientConnectionManager() | |
{ | |
try | |
{ | |
String defaultType = KeyStore.getDefaultType(); | |
KeyStore trustedStore = KeyStore.getInstance(defaultType); | |
InputStream certificateStream = context.getResources().openRawResource(R.raw.keystore); | |
trustedStore.load(certificateStream, "password".toCharArray()); | |
certificateStream.close(); | |
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(trustedStore); | |
sslSocketFactory.setHostnameVerifier((X509HostnameVerifier) SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); | |
SchemeRegistry registry = new SchemeRegistry(); | |
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 8080)); | |
registry.register(new Scheme("https", sslSocketFactory, 8443)); | |
return new SingleClientConnManager(getParams(), registry); | |
} | |
catch (Exception e) | |
{ | |
throw new AssertionError(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment