c# - Httpwebrequest 问题 (503)

标签 c# winforms httpwebrequest webexception

我正在使用 HttpWebrequest 从 google 获取结果。我使用代理来获取数据。现在有一个奇怪的问题,对于一些查询它返回数据而对于一些它抛出异常远程服务器返回错误:(503) 服务器不可用。。有人可能认为代理不好,但是当你把它放在 Internet Explorer 中然后你打开谷歌时它就在那里。然后没有 503 错误。但是 httpwebrequest 在某些查询中给出它。即如果你打算得到

http://www.google.com/search?q=site:http://www.yahoo.com 

它会在你去的地方抛出异常

http://www.google.com/search?q=info:http://www.yahoo.com

有效。

到目前为止我的代码是

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(file);
                request.ProtocolVersion = HttpVersion.Version11;
                request.Method = "GET";
               request.KeepAlive = false;
                request.ContentType = "text/html";
                request.Timeout = 1000000000;
                request.ReadWriteTimeout = 1000000000;
                request.UseDefaultCredentials = true;
                request.Credentials = CredentialCache.DefaultCredentials;
    Uri newUri = new Uri("http://" + proxy[selectedProxy].ProxyAddress.Trim() + "/");
                    WebProxy myProxy = new WebProxy();
                    myProxy.Credentials = CredentialCache.DefaultCredentials;
                    myProxy.Address = newUri;
                    request.Proxy = myProxy;
 WebResponse response = request.GetResponse();
                    // System.Threading.Thread.Sleep(Delay);
                    StreamReader reader = null;
                    string data = null;
                    reader = new StreamReader(response.GetResponseStream());
                        data = reader.ReadToEnd();

最佳答案

您收到“抱歉,您是垃圾邮件”的提示,需要输入验证码才能继续或更改代理。出于某种原因,当您收到 503 错误时,默认情况下您无法拉取页面内容,但如果您在浏览器中执行相同的操作,内容将显示给您。

关于c# - Httpwebrequest 问题 (503),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6405095/

相关文章:

c# - .NET 编译程序集来源 : Determine which source failed?

c# - WindowFromPoint 在 64 位 .NET Framework 上无法正常工作

vb.net - 以编程方式向面板添加控件

python - python 中的 HTTP 请求超时

c# - 使用 HttpWebRequest 登录页面

c# - 为什么我的 MenuStrip 在第一次点击时出现在错误的位置?

c# - 将 XmlReader XML 写入 Visual Studio 中的即时窗口?

c# - C# 中抽象工厂设计模式的真实世界示例

c# - 如何在 Windows 窗体 C# 中同时将两个文件发布到 API

c# - 自定义身份验证模块仅在存在凭据时调用