.net - System.Net.WebClient 请求得到 403 Forbidden 但浏览器没有使用 Apache 服务器

标签 .net apache http-headers webclient http-status-code-403

奇怪的是,我正在尝试阅读许多不同网站的 部分,而一种特定类型的服务器 Apache 有时会禁止使用 403 代码。并非所有 apache 服务器都这样做,因此它可能是配置设置或服务器的特定版本。

然后,当我使用 Web 浏览器(例如 Firefox)检查 url 时,页面加载正常。代码大概是这样的:

var client = new WebClient();
var stream = client.OpenRead(new Uri("http://en.wikipedia.org/wiki/Barack_Obama"));

通常,403 是访问权限失败之类的事情,但这些通常是不安全的页面。我认为 Apache 正在过滤请求 header 中的某些内容,因为我不想创建任何内容。

也许对 Apache 有更多了解的人可以给我一些关于标题中缺少的内容的想法。我想保持标题尽可能小以最小化带宽。

谢谢

最佳答案

尝试设置 UserAgent header :

string _UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
client.Headers.Add(HttpRequestHeader.UserAgent, _UserAgent);

关于.net - System.Net.WebClient 请求得到 403 Forbidden 但浏览器没有使用 Apache 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2316111/

相关文章:

.net - 如何处理异步套接字中的超时?

c# - HttpClient 检索所有 header

azure - 使用 postman 对 Azure 存储模拟器进行授权?

apache - SVN 重定向周期

iphone - 使用 CakePHP 的媒体 View 将视频提供给 iPad/iPhone

.net - 如何分析声音并存储结果?

c# - 如何创建一个有边框但没有标题栏的表单? (如 Windows 7 上的音量控制)

c# - 自动加载 32 位/64 位程序集

apache - Xampp中的phpMyAdmin无法正常工作

apache - Apache 中的快速 CGI : Couldn't bind unix domain socket