Reputation: 21
The first time I call this function everything works perfect. When I call it the second time I get an exception Host is not responding correclty I tried everything for hours but I dont get it to work. Is it the website or is something wrong with my code?
string url = "https://www.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp";
string website = "";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
httpRequest.Timeout = 5000;
using (var response = (HttpWebResponse)httpRequest.GetResponse())
{
using (StreamReader Reader = new StreamReader(response.GetResponseStream()))
{
website = Reader.ReadToEnd();
}
}
httpRequest.Abort();
Upvotes: 2
Views: 535
Reputation: 100
Please, on every question that you are going to do here, try to put as maximum of details as possible. It will become easier for us to help you on your problems. Especially the exceptions that you are having doing the development.
About your code, the implementation of that is not recommended for Microsoft. Looking at the docs https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest?view=netframework-4.8 there is a part that says: We don't recommend that you use HttpWebRequest for new development. Instead, use the System.Net.Http.HttpClient class.
Try to change your implementation to use the class HttpClient, and see if the error is going to occur again.
Upvotes: 1