internal static async Task <HttpRequestResult <TSchema> > ExecuteGetAsync <TSchema>(IParser <TSchema> parser, Uri uri, IDictionary <string, string> headers = null) where TSchema : SchemaBase
        {
            var settings = new HttpRequestSettings()
            {
                RequestedUri = uri
            };

            if (headers != null && headers.Count > 0)
            {
                foreach (var item in headers)
                {
                    settings.Headers[item.Key] = item.Value;
                }
            }

            HttpRequestResult httpResult = await DownloadAsync(settings);

            HttpRequestResult <TSchema> result;

            result = new HttpRequestResult <TSchema>(httpResult);
            if (httpResult.Success)
            {
                var items = await parser.ParseAsync(httpResult.Result);

                if (items == null)
                {
                    items = new TSchema[0];
                }
                result.Items = items;
            }

            return(result);
        }
Beispiel #2
0
        internal static async Task <HttpRequestResult> DownloadAsync(HttpRequestSettings settings)
        {
            var result = new HttpRequestResult();
            HttpResponseMessage response = await GetResponseMessage(settings);

            result.StatusCode = response.StatusCode;
            FixInvalidCharset(response);
            var content = await response.Content.ReadAsStringAsync();

            result.Result = content;
            return(result);
        }
Beispiel #3
0
        internal static async Task <HttpRequestResult> DownloadAsync(HttpRequestSettings settings)
        {
            var result = new HttpRequestResult();

            var filter = new HttpBaseProtocolFilter();

            filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;

            var httpClient = new HttpClient(filter);

            AddRequestHeaders(httpClient, settings);

            HttpResponseMessage response = await httpClient.GetAsync(settings.RequestedUri);

            result.StatusCode = response.StatusCode;
            FixInvalidCharset(response);
            result.Result = await response.Content.ReadAsStringAsync();

            return(result);
        }
Beispiel #4
0
        internal static async Task<HttpRequestResult> DownloadAsync(HttpRequestSettings settings)
        {
            var result = new HttpRequestResult();

            var filter = new HttpBaseProtocolFilter();
            filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;

            var httpClient = new HttpClient(filter);

            if (!string.IsNullOrEmpty(settings.UserAgent))
            {
                httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(settings.UserAgent);
            }

            HttpResponseMessage response = await httpClient.GetAsync(settings.RequestedUri);
            result.StatusCode = response.StatusCode;
            FixInvalidCharset(response);
            result.Result = await response.Content.ReadAsStringAsync();

            return result;
        }