예제 #1
0
        private OkHttpClient CreateOkHttpClientInstance()
        {
            var builder = new OkHttpClient.Builder()
                          .ConnectTimeout(100, TimeUnit.Seconds)
                          .WriteTimeout(100, TimeUnit.Seconds)
                          .ReadTimeout(100, TimeUnit.Seconds)
                          .CookieJar(new JavaNetCookieJar(new Java.Net.CookieManager()));

            if (_certificatePinnerBuilder.IsValueCreated)
            {
                builder.CertificatePinner(_certificatePinnerBuilder.Value.Build());
            }

            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                // Support TLS1.2 on Android versions before Lollipop
                builder.SslSocketFactory(new TlsSslSocketFactory(KeyManagers, TrustManagers), _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager());
            }
            else if (_keyMgrFactory != null || _trustMgrFactory != null)
            {
                var context = SSLContext.GetInstance("TLS");
                context.Init(KeyManagers, TrustManagers, null);
                builder.SslSocketFactory(context.SocketFactory, _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager());
            }

            return(builder.Build());
        }
        private static OkHttpClient CreateOkHttpClientInstance()
        {
            var builder = new OkHttpClient.Builder()
                          .ConnectTimeout(100, TimeUnit.Seconds)
                          .WriteTimeout(100, TimeUnit.Seconds)
                          .ReadTimeout(100, TimeUnit.Seconds);

            builder.CookieJar(new NativeCookieJar());
            if ((int)Build.VERSION.SdkInt < 21)
            {
                // Support TLS1.2 on Android versions before Lollipop
                builder.SslSocketFactory(new TlsSslSocketFactory(), TlsSslSocketFactory.GetSystemDefaultTrustManager());
            }
            return(builder.Build());
        }
예제 #3
0
        private OkHttpClient CreateOkHttpClientInstance()
        {
            var builder = new OkHttpClient.Builder()
                          .ConnectTimeout(100, TimeUnit.Seconds)
                          .WriteTimeout(100, TimeUnit.Seconds)
                          .ReadTimeout(100, TimeUnit.Seconds)
                          .FollowRedirects(AllowAutoRedirect)
                          .AddInterceptor(new DecompressInterceptor(_logger));

            if (UseCookies)
            {
                builder.CookieJar(new JavaNetCookieJar(new Java.Net.CookieManager()));
            }

            if (!UseProxy)
            {
                builder.Proxy(Java.Net.Proxy.NoProxy);
            }
            else if (Proxy is WebProxy webProxy)
            {
                var proxyAddress = new InetSocketAddress(webProxy.Address.Host, webProxy.Address.Port);
                builder.Proxy(new Proxy(Java.Net.Proxy.Type.Http, proxyAddress));
            }

            if (_certificatePinnerBuilder.IsValueCreated)
            {
                builder.CertificatePinner(_certificatePinnerBuilder.Value.Build());
            }

            if (_keyMgrFactory != null || _trustMgrFactory != null)
            {
                var context = SSLContext.GetInstance("TLS");
                context.Init(KeyManagers, TrustManagers, null);
                builder.SslSocketFactory(context.SocketFactory, _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager());
            }

            return(builder.Build());
        }