Ejemplo n.º 1
0
        public HttpClient CreateClient(string resource = null)
        {
            resource = resource?.Trim('/');

            if (!string.IsNullOrEmpty(resource))
            {
                resource = resource + "/";
            }

            var handler = _httpMessageHandlerFactory();

            var client = new HttpClient(handler)
            {
                BaseAddress = new Uri($"{_options.EndpointUri}/{resource}"),
            };

            var authorizationHeader = _options.GetAuthorizationHeader();

            client.DefaultRequestHeaders.Add("Authorization", authorizationHeader);

            client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));

            if (_options.Timeout != null)
            {
                client.Timeout = _options.Timeout.Value;
            }

            return(client);
        }
        public HttpClient CreateClient(string resource = null)
        {
            var formattedResource = resource?
                                    .Trim('/');

            if (!string.IsNullOrEmpty(formattedResource))
            {
                formattedResource = formattedResource + "/";
            }

            var client = _httpClientFactory
                         .CreateClient("zendeskApiClient");

            client.BaseAddress = new Uri($"{_options.EndpointUri}/{formattedResource}");

            var authorizationHeader = _options
                                      .GetAuthorizationHeader();

            client.DefaultRequestHeaders
            .Add(
                "Authorization",
                authorizationHeader);

            client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));

            if (_options.Timeout != null)
            {
                client.Timeout = _options.Timeout.Value;
            }

            return(client);
        }
Ejemplo n.º 3
0
        public HttpClient CreateClient(string resource = null)
        {
            var handler = new HttpClientHandler();

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            resource = resource?.Trim('/');

            if (!string.IsNullOrEmpty(resource))
            {
                resource = resource + "/";
            }

            var client = new HttpClient(handler)
            {
                BaseAddress = new Uri($"{_options.EndpointUri}/{resource}"),
            };

            var authorizationHeader = _options.GetAuthorizationHeader();

            client.DefaultRequestHeaders.Add("Authorization", authorizationHeader);

            client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/json"));

            if (_options.Timeout != null)
            {
                client.Timeout = _options.Timeout.Value;
            }

            return(client);
        }