Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleHttpClient"/> class.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="timeout">The timeout.</param>
        public SimpleHttpClient(CancellationToken cancellationToken, TimeSpan timeout)
        {
            try
            {
                this.handler = new SimpleHttpRedirectHandler();
                this.client  = new HttpClient(this.handler);

                this.Timeout                   = timeout;
                this.cancellationToken         = cancellationToken;
                this.Method                    = HttpMethod.Get;
                this.Headers                   = new Dictionary <string, string>();
                this.ContentType               = string.Empty;
                this.SkipCertificateValidation = false;
            }
            catch
            {
                if (this.handler != null)
                {
                    this.handler.Dispose();
                }

                if (this.client != null)
                {
                    this.client.Dispose();
                }

                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleHttpClient"/> class.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="timeout">The timeout.</param>
        public SimpleHttpClient(CancellationToken cancellationToken, TimeSpan timeout, bool skipCertificateValidation)
        {
            try
            {
                this.handler = new SimpleHttpRedirectHandler();
                //if (!validateClientCertificate)
                //    this.handler.ServerCertificateCustomValidationCallback = delegate { return true; };
                this.client = new HttpClient(this.handler);

                this.Timeout           = timeout;
                this.cancellationToken = cancellationToken;
                this.Method            = HttpMethod.Get;
                this.Headers           = new Dictionary <string, string>();
                this.ContentType       = string.Empty;
                //this.SkipCertificateValidation = false;
                this.SkipCertificateValidation = skipCertificateValidation;
            }
            catch
            {
                if (this.handler != null)
                {
                    this.handler.Dispose();
                }

                if (this.client != null)
                {
                    this.client.Dispose();
                }

                throw;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleHttpClient"/> class.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="timeout">The timeout.</param>
        public SimpleHttpClient(CancellationToken cancellationToken, TimeSpan timeout)
        {
            try
            {
                this.handler = new SimpleHttpRedirectHandler();
                this.client = new HttpClient(this.handler);

                this.Timeout = timeout;
                this.cancellationToken = cancellationToken;
                this.Method = HttpMethod.Get;
                this.Headers = new Dictionary<string, string>();
                this.ContentType = string.Empty;
                this.SkipCertificateValidation = false;
            }
            catch
            {
                if (this.handler != null)
                {
                    this.handler.Dispose();
                }

                if (this.client != null)
                {
                    this.client.Dispose();
                }

                throw;
            }
        }
Esempio n. 4
0
 public SimpleHttpClient(HttpClient httpClient,
                         IOptions <CloudFoundryServicesOptions> cfOptions, IOptions <CfServiceBinding> cfServiceOptions,
                         ILogger <SimpleHttpClient> logger, SimpleHttpRedirectHandler httpHandler)
 {
     _logger = logger;
     if (cfOptions == null)
     {
         logger.LogCCInformation("CF options not found");
     }
     else if (cfServiceOptions == null)
     {
         logger.LogCCInformation("VCAP services not found");
     }
     else
     {
         var credentials = cfOptions?.Value.GetServicesList()?.FirstOrDefault(service =>
                                                                              service.Name.CompareTo(cfServiceOptions?.Value?.ServiceBinding) == 0).Credentials;
         var cfConfig = CFConfiguration.GetConfigurationFromCredential(credentials);
         handler = httpHandler;
         SetClassProperties(httpClient, cfConfig);
     }
 }