从浏览器打开公共页面工作正常.
使用WebClient下载同一页面抛出 - (403)禁止.
这里发生了什么 ?
以下是Web上特定页面的快速复制/粘贴示例(在控制台应用程序上使用):
try
{
WebClient webClient = new WebClient();
string content = webClient.DownloadString("http://he.wikisource.org/wiki/%D7%A9%D7%95%D7%9C%D7%97%D7%9F_%D7%A2%D7%A8%D7%95%D7%9A_%D7%90%D7%95%D7%A8%D7%97_%D7%97%D7%99%D7%99%D7%9D_%D7%90_%D7%90");
}
catch (Exception ex)
{
throw;
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*ith 46
我刚刚尝试使用Fiddler运行以查看响应,并返回以下通知和状态代码.
脚本应使用带有联系信息的信息性用户代理字符串,否则它们可能会被IP阻止,恕不另行通知.
这有效.
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Only a test!");
string content = webClient.DownloadString("http://he.wikisource.org/wiki/%D7%A9%D7%95%D7%9C%D7%97%D7%9F_%D7%A2%D7%A8%D7%95%D7%9A_%D7%90%D7%95%D7%A8%D7%97_%D7%97%D7%99%D7%99%D7%9D_%D7%90_%D7%90");
Run Code Online (Sandbox Code Playgroud)