Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我收到与WebClient不兼容的浏览器消息?_C#_Http Headers_Webclient_Microsoft Edge_Dotnet Httpclient - Fatal编程技术网

C# 为什么我收到与WebClient不兼容的浏览器消息?

C# 为什么我收到与WebClient不兼容的浏览器消息?,c#,http-headers,webclient,microsoft-edge,dotnet-httpclient,C#,Http Headers,Webclient,Microsoft Edge,Dotnet Httpclient,我正在尝试使用WebClient使用.NET刮取网页。但是,我不断收到一条不兼容的浏览器消息。请看下面的HTML源代码(不幸的是,我不能共享链接,因为它是内部的)。不知何故,服务器认为我正在使用不兼容版本的IE。我尝试设置用户代理,但没有任何效果 <!--[if lt IE 10]> <div id="incompatible_ie" style="display:block;font-family:Calibri,sans-serif;font-size:14px;

我正在尝试使用WebClient使用.NET刮取网页。但是,我不断收到一条不兼容的浏览器消息。请看下面的HTML源代码(不幸的是,我不能共享链接,因为它是内部的)。不知何故,服务器认为我正在使用不兼容版本的IE。我尝试设置用户代理,但没有任何效果

<!--[if lt IE 10]>

    <div id="incompatible_ie" style="display:block;font-family:Calibri,sans-serif;font-size:14px;text-align:center;margin:20% 0 5em;color:#777">

      <div style="font-size:xx-large;margin-bottom:2em">HOME</div>

      <div>Your browser is not supported by the application.<br>We recommend you use Google Chrome or IE11 without Compatibility Mode.</div>

    </div>

    <script>

      console && console.error("Unsupported browser: Removing #root element to prevent React from loading.");

      document.getElementsByTagName("body")[0].removeChild(document.getElementById("root"));

    </script>

    <![endif]-->

你们真的能在微软的Edge中看到有问题的页面吗?显然服务器认为你们假装是浏览器是不够的。使用Fiddler(或任何其他工具捕获/比较HTTP流量),捕获浏览器和代码中的流量,然后发布比较结果,以便有人可以帮助您伪造其余的标题。@是的,我可以在Edge和Chrome中查看页面。@Joey在设置可接受的用户代理字符串后,我从未遇到过此问题。但是我使用
HttpWebRequest
/
HttpWebResponse
而不是
WebClient
。谢谢,我试过了,但结果一样。
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763");
string html = client.DownloadString(path);