我HttpWebrequest
用来从谷歌获取结果。我使用代理来获取数据。现在有一个奇怪的问题,对于某些查询它返回数据,而对于某些它抛出异常The remote server returned an error: (503) Server Unavailable.
。有人可能认为代理不好,但是当你把它放在 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();