Hi,
Please set webRequest.Timeout to 0,so it will wait till request is completed.
C#
WebRequest webRequest = WebRequest.Create(ytLink);
webRequest.Timeout = 0;
//webRequest.r
webRequest.Credentials = CredentialCache.DefaultCredentials;
WebResponse webResponse = webRequest.GetResponse();
Console.WriteLine(((HttpWebResponse)webResponse).StatusDescription);
Stream dataStream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
webResponse.Close();
Note:
The GetResponse()
method is a synchronous method that will only return after the server sends a reply.
The BeginGetResponse()
method is an asynchronous method that will return immediately, before the server replies.