Esempio n. 1
0
        /// <summary>
        /// Creates a HttpClientDownloader instance
        /// </summary>
        /// <param name="AddDefaultHeaders">Specify when initialize some default headers</param>
        public HttpClientDownloader(bool AddDefaultHeaders = false)
        {
            var hdl = new HttpClientHandler()
            {
                AllowAutoRedirect = false
            };

            httpClient            = new HttpClient(hdl);
            cancellationToken     = new CancellationTokenSource();
            IncludeRequestHeaders = new HeaderCollection();
            if (AddDefaultHeaders)
            {
                IncludeRequestHeaders.AddBaseRequestHeaders();
                IncludeRequestHeaders["Accept-Encoding"] = "gzip, deflate";
            }
        }
        /// <summary>
        /// Create a new instance
        /// </summary>
        public RequestHelper(bool UseCookies = false)
        {
            var hdl = new HttpClientHandler()
            {
                AllowAutoRedirect = true
            };

            if (UseCookies)
            {
                Cookies             = new CookieContainer();
                hdl.CookieContainer = Cookies;
                hdl.UseCookies      = true;
            }
            else
            {
                hdl.UseCookies = false;
            }
            httpClient     = new HttpClient(hdl);
            RequestHeaders = new HeaderCollection();
            RequestHeaders.AddBaseRequestHeaders();
            RequestHeaders["Accept-Encoding"] = "gzip, deflate";
        }