I am using HttpWebrequest
to GET the result from google.I use proxies to get the data.now there is a strange problem that for some queries it return the data and for some it throws the exception The remote server returned an error: (503) Server Unavailable.
. One might think that proxy is bad but when you put it in internet explorer then you open google it is there.no 503 error then.but httpwebrequest
gives it on certain query.i.e if you intend to get
http://www.google.com/search?q=site:http://www.yahoo.com
it would throw exception where as if you go for
http://www.google.com/search?q=info:http://www.yahoo.com
it works.
my code so far is
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();