コード例 #1
0
ファイル: DownloadService.cs プロジェクト: davidortinau/wpbf
        public async Task <string> Download(string url, CancellationTokenSource token = null, SessionCookie sessionCookie = null)
        {
            _currentToken = token ?? new CancellationTokenSource();

            var handler      = _modernModernHttpClient.GetNativeHandler();
            var outerHandler = new RetryHandler(handler, 3);
            var client       = _modernModernHttpClient.Get(outerHandler);

            if (sessionCookie != null)
            {
                var cookieJar = new CookieContainer();
                cookieJar.Add(new Uri(Constants.BASE_URI), new Cookie(sessionCookie.Name, sessionCookie.Value));
            }

            var msg = await client.GetAsync(url, _currentToken.Token);

            if (!msg.IsSuccessStatusCode)
            {
                return("Something derped");
            }

            var result = await msg.Content.ReadAsStringAsync();

            return(result);
        }
コード例 #2
0
        public async Task <string> Download(string url, CancellationTokenSource token = null)
        {
            _currentToken = token ?? new CancellationTokenSource();

            var handler      = _modernModernHttpClient.GetNativeHandler();
            var outerHandler = new RetryHandler(handler, 3);
            var client       = _modernModernHttpClient.Get(outerHandler);
            var msg          = await client.GetAsync(url, _currentToken.Token);

            if (!msg.IsSuccessStatusCode)
            {
                return("Something derped");
            }

            var result = await msg.Content.ReadAsStringAsync();

            return(result);
        }