【发布时间】:2020-01-23 18:07:27
【问题描述】:
我第一次调用这个函数时一切正常。 当我第二次调用它时,我得到一个异常主机没有响应正确 我尝试了几个小时,但我没有让它工作。 是网站还是我的代码有问题?
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();
【问题讨论】:
-
你为什么要调用 httpRequest.Abort()?
-
您能否发布有关您遇到的错误/异常的更多详细信息?
-
请提供完整的代码?您应该知道微软建议使用 http 客户端进行新的开发。
标签: c# web-scraping webrequest