Ejemplo n.º 1
0
 public static void AddDefaultRequestHeaders(this HttpClient httpClient, IHttpClientOptions options)
 {
     if (options != null && options.CompressionOptions.DecompressionMethods != null)
     {
         foreach (var encoding in options.CompressionOptions.DecompressionMethods)
         {
             httpClient.DefaultRequestHeaders.Add(name: "Accept-Encoding", value: encoding.ToString());
         }
     }
 }
Ejemplo n.º 2
0
        public JsonHttpClient(IHttpClientOptions clientOptions)
        {
            // Create the inner HTTP client...
            this.httpClient = new HttpClient();

            // Configure the retry policy...
            this.httpRetryPolicy = Policy.Handle <HttpRequestException>()
                                   .ConfigureExponentialBackOffRetryPolicy(clientOptions.MaximumRetryAttempts);

            // Always include the "application/json" accept header...
            this.httpClient.DefaultRequestHeaders.Accept.Clear();
            this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(JsonMediaType));
        }
Ejemplo n.º 3
0
        public static async Task <T> Get <T>(IHttpClientOptions httpClientOptions)
        {
            Object content = "";

            using (HttpClient _httpClient = new HttpClient())
            {
                if (httpClientOptions.OutPutFormat == OutPutFormat.String)
                {
                    content = await _httpClient.GetStringAsync(httpClientOptions.URL);
                }
                else if (httpClientOptions.OutPutFormat == OutPutFormat.HttpResponse)
                {
                    content = await _httpClient.GetAsync(httpClientOptions.URL, HttpCompletionOption.ResponseContentRead);
                }
                else if (httpClientOptions.OutPutFormat == OutPutFormat.XML)
                {
                }
                else if (httpClientOptions.OutPutFormat == OutPutFormat.Stream)
                {
                }
            }
            return((T)Convert.ChangeType(content, typeof(T)));
        }