从浏览器打开公共(public)页面可以正常工作。

使用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;
}

最佳答案

我刚刚在Fiddler运行时尝试了一下,以查看响应,并且它返回以下带有状态代码的通知。



这有效。

    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");

关于c# - WebClient-远程服务器返回错误: (403) Forbidden,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2794260/

10-10 11:18