Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
    protected ClientConnectionManager createClientConnectionManager()
    {
        SchemeRegistry registry = new SchemeRegistry();

        registry.register(new Scheme("http", PlainSocketFactory
                                     .getSocketFactory(), 80));
        // Register for port 443 our SSLSocketFactory with our keystore
        // to the ConnectionManager
        registry.register(new Scheme("https", newSslSocketFactory(), 443));
        return(new SingleClientConnManager(getParams(), registry));
    }