Beispiel #1
0
        public async Task <string> GetContentAsync(string url)
        {
            var uri = new Uri(url);

            PublishHeaders(url);
            switch (HttpProvider)
            {
            case EnumHttpProvider.HttpClient:

                var ret = await httpClient.GetAsync(url);

                return(await ret.Content.ReadAsStringAsync());

            case EnumHttpProvider.WebClient:
                return(Encoding.Default.GetString(await webClient.DownloadDataTaskAsync(uri)));

            case EnumHttpProvider.AngleSharp:

                var browse = await angleSharpClient.OpenAsync(url);

                return(browse.Source.Text);

            case EnumHttpProvider.BetterWebClient:

                if (this.HttpMethod == "POST")
                {
                    var msg    = Encoding.UTF8.GetBytes(this.HttpBody);
                    var result = await betterWebClient.UploadDataTaskAsync(uri, "POST", msg);

                    Cookies = betterWebClient.CookieContainer.GetCookieHeader(uri);

                    return(Encoding.Default.GetString(result));
                }

                var data = await betterWebClient.DownloadDataTaskAsync(uri);

                Cookies = betterWebClient.CookieContainer.GetCookieHeader(uri);


                return(Encoding.Default.GetString(data));

            case EnumHttpProvider.ChromeHeadless:
                return(await chromeHeadlessClient.GetContentAsync(uri.ToString()));

            case EnumHttpProvider.ChromeHeadlessPersistent:
                return(await chromeHeadlessPersistentClient.GetContentAsync(uri.ToString()));
            }

            throw new NotImplementedException();
        }