c# - HttpWebResponse 超时

标签 c# .net web

我在下面的代码中收到超时异常。只有这个网站有问题。有什么问题?

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

enter image description here

..它起作用了

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/

相关文章:

c# - 如何在 Linq where 子句中指定动态字段名称?

mysql - 上传网站

html - Zurb Foundation 4 - 如何创建全高柱

php - 网站翻译器

c# - Uri.ToString() 和 Uri.AbsoluteUri 有什么区别?

c# - SQL Server 连接数有限制吗?

c# - 在 mysql 连接上“使用”

.net - "Value does not fall within expected range"在运行时错误中是什么意思?

c# - 在间隔异步中并行运行一些函数?

c# - 如何在 Active Directory 中更改用户的登录名