Answer the question
In order to leave comments, you need to log in
Why is GetResponseAsync terminating the process?
There is a code:
string html = await GetDataAsync(url, cookie);
Console.WriteLine(html);
async Task<string> GetDataAsync(string url, string cookie) {
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "GET";
webRequest.Headers["UserAgent"] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(new Uri(url), new Cookie("express.sid", cookie));
var response = await webRequest.GetResponseAsync();
return new StreamReader(
response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
Answer the question
In order to leave comments, you need to log in
Replaced
on the
var response = webRequest.GetResponseAsync();
response.Wait();
response.Result();
and if without cookies and user agent Yandex request what will happen?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question