async Task LoadAsync(int carId, String url, string userAgent, CancellationToken cancel) { var handler = new HttpClientHandler { AllowAutoRedirect = false }; var http = new HttpClient(handler); http.DefaultRequestHeaders.Add("User-Agent", userAgent ); //Get a correct URL from the given one (e.g. transform codeproject.com to http://codeproject.com) var uri = Sanitize(url); //Make the request var request = await http.GetAsync(uri); //var request = await http.GetStringAsync(uri); cancel.ThrowIfCancellationRequested(); //Get the response stream var response = await request.Content.ReadAsStringAsync(); cancel.ThrowIfCancellationRequested(); var html = new Html { CarId = carId, html = response, Processed = false }; var data = new Data(); data.InsertHtmlData(html); cancel.ThrowIfCancellationRequested(); /* Use the document */ }
private async Task LoadAsync(String url, CancellationToken cancel) { var handler = new HttpClientHandler {AllowAutoRedirect = false}; var http = new HttpClient(handler); http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident / 6.0)"); //Get a correct URL from the given one (e.g. transform codeproject.com to http://codeproject.com) var uri = Sanitize(url); //Make the request var request = await http.GetAsync(uri); //var request = await http.GetStringAsync(uri); cancel.ThrowIfCancellationRequested(); //Get the response stream var response = await request.Content.ReadAsStringAsync(); cancel.ThrowIfCancellationRequested(); var html = new Html(); txtHtml.Text = response; html.CarId = Convert.ToInt32(textBox1.Text); html.html = response; html.Processed = false; var data = new Data(); data.InsertHtmlData(html); cancel.ThrowIfCancellationRequested(); /* Use the document */ }