Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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# 如何绕过锁并从站点C获取html#_C# - Fatal编程技术网

C# 如何绕过锁并从站点C获取html#

C# 如何绕过锁并从站点C获取html#,c#,C#,我需要从网站获取html。我通常使用WebClient.DownloadString(string)。但作为回答,我得到如下html页面: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <div

我需要从网站获取html。我通常使用
WebClient.DownloadString(string)
。但作为回答,我得到如下html页面:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">          
    </head>
    <body>
        <div align="center"><h3>Access is blocked by site administrator [27]</h3></div>
    </body>
</html>
我尝试使用
HttpClient().GetStringAsync(新Uri(url))
,但结果相同


对不起我的英语。感谢您的回答。

看起来该网站需要一个
用户代理
请求头。因此,您可以将其设置为这样,以诱使站点认为请求来自浏览器:

client.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";

看起来站点需要一个
用户代理
请求头。因此,您可以将其设置为这样,以诱使站点认为请求来自浏览器:

client.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";

您能在浏览器中打开站点吗?我的IP未被阻止。我可以在浏览器中打开此网站。它是哪个网站?好的,签出用户代理请求标题的我的答案。您可以在浏览器中打开此网站吗?我的IP未被阻止。我可以在浏览器中打开此网站。它是哪个网站?好的,请签出我对用户代理请求标题的回答。