Ejemplo n.º 1
0
        public override async Task <string> GetResponseText(Uri uri, searchfight.Utilities.StringDictionary headers)
        {
            using (HttpClient client = new HttpClient(new HttpClientHandler()
            {
                AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip
            }))
            {
                if (Timeout > 0)
                {
                    client.Timeout = TimeSpan.FromMilliseconds(Timeout);
                }
                else
                {
                    client.Timeout = TimeSpan.FromMilliseconds(DefaultTimeout);
                }

                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                    }
                }

                try
                {
                    return(await client.GetStringAsync(uri));
                }
                catch (HttpRequestException ex)
                {
                    throw new WebRequestException(ex.Message, ex);
                }
                catch (TaskCanceledException ex)
                {
                    throw new WebRequestException("The request timed out.", ex);
                }
            }
        }
Ejemplo n.º 2
0
 public abstract Task <string> GetResponseText(Uri uri, searchfight.Utilities.StringDictionary headers);