我在下面的代码中收到超时异常。只有这个网站有问题。有什么问题?
string ackoURL = "https://www.zomato.com/sk/brno/u-heligonky-z%C3%A1brdovice-brno-st%C5%99ed/denn%C3%A9-menu";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ackoURL);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
//this code is never executed
}
我尝试修改 SecurityProtocol、KeepAlive 和类似的东西。没有成功。
最佳答案
它正在等待这些 header
..它起作用了
Uri u = new Uri("https://www.zomato.com/sk/brno/u-heligonky-z%C3%A1brdovice-brno-st%C5%99ed/denn%C3%A9-menu");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(u);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.Headers.Add("Accept-Language", "en-gb,en;q=0.5");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using(Stream stream = response.GetResponseStream())
{
using(StreamReader reader= new StreamReader(stream))
{
var result = reader.ReadToEnd();
}
}
}
关于c# - HttpWebResponse 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42400295/