Wednesday, June 25, 2014

Handling No peer certificate

Handling No peer certificate
>Only use for debugging purpose, Don't use for production.

Step 1:
DefaultHttpClient httpClient = (DefaultHttpClient) getNewHttpClient();

Step 2:
public HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore
trustStore.load(null, null);

SSLSocketFactory sf = new MySSLSocketFactory(trustStore);

HttpParams params = new BasicHttpParams();
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));

ClientConnectionManager ccm = new ThreadSafeClientConnManager(
params, registry);

return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();

1 comment:

  1. Hey dude…good article. You are the best writer that I have come across so far. You have a knack for words, I must say. I have bookmarked your web page. Please keep writing such wonderful blogs. For freelancers, who are working to earn the extra bucks…your article is worth millions of dollars. You are my FPG (friend, philosopher and guide)! I have wholeheartedly stepped into the freelance zone and checked out some sites like buy 1000 youtube subscribers,creative flyer design, and You have woken me up to the possibilities of marketplaces. Thank you and keep posting!