private static DefaultHttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.GetInstance(KeyStore.DefaultType); trustStore.Load(null, null); Org.Apache.Http.Conn.Ssl.SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.HostnameVerifier = Org.Apache.Http.Conn.Ssl.SSLSocketFactory.AllowAllHostnameVerifier; IHttpParams parameters = new BasicHttpParams(); HttpProtocolParams.SetVersion(parameters, Org.Apache.Http.HttpVersion.Http11); HttpProtocolParams.SetContentCharset(parameters, HTTP.Utf8); SchemeRegistry registry = new SchemeRegistry(); registry.Register(new Scheme("http", PlainSocketFactory.SocketFactory, 80)); registry.Register(new Scheme("https", sf, 443)); IClientConnectionManager ccm = new ThreadSafeClientConnManager(parameters, registry); return new DefaultHttpClient(ccm, parameters); } catch (Exception e) { return new DefaultHttpClient(); } }
public virtual HttpClient GetHttpClient() { // workaround attempt for issue #81 // it does not seem like _not_ using the ThreadSafeClientConnManager actually // caused any problems, but it seems wise to use it "just in case", since it provides // extra safety and there are no observed side effects. BasicHttpParams @params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.Register(new Apache.Http.Conn.Scheme.Scheme("http", PlainSocketFactory .GetSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.GetSocketFactory(); schemeRegistry.Register(new Apache.Http.Conn.Scheme.Scheme("https", this.sslSocketFactory == null ? sslSocketFactory : this.sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(@params, schemeRegistry ); DefaultHttpClient client = new DefaultHttpClient(cm, @params); // synchronize access to the cookieStore in case there is another // thread in the middle of updating it. wait until they are done so we get their changes. lock (this) { client.SetCookieStore(cookieStore); } return(client); }
public virtual HttpClient GetHttpClient() { // workaround attempt for issue #81 // it does not seem like _not_ using the ThreadSafeClientConnManager actually // caused any problems, but it seems wise to use it "just in case", since it provides // extra safety and there are no observed side effects. BasicHttpParams @params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.Register(new Apache.Http.Conn.Scheme.Scheme("http", PlainSocketFactory .GetSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.GetSocketFactory(); schemeRegistry.Register(new Apache.Http.Conn.Scheme.Scheme("https", this.sslSocketFactory == null ? sslSocketFactory : this.sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(@params, schemeRegistry ); DefaultHttpClient client = new DefaultHttpClient(cm, @params); // synchronize access to the cookieStore in case there is another // thread in the middle of updating it. wait until they are done so we get their changes. lock (this) { client.SetCookieStore(cookieStore); } return client; }
public static Scheme register(this SchemeRegistry schemeregistry, Scheme sch) { return(schemeregistry.Register(sch)); }