我想使用免费代理服务器在谷歌搜索。这是我的代码:
string SearchResults = "http://google.com/search?q=" + textBox1.Text.Trim();
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create(SearchResults);
request.Method = "GET";
request.Proxy= new WebProxy("http://209.150.146.27:8080", true);
//here is the issue
response = (HttpWebResponse)request.GetResponse();
我该怎么做才能解决这个问题? 我使用这个代理服务器列表: www.gatherproxy.com/proxylist/anonymity/?t=Transparent
答案 0 :(得分:1)
代理服务器存在问题
它返回503错误代码或只是不可用。
当我删除request.Proxy= new WebProxy("http://209.150.146.27:8080", true);
时,一切正常。
当我使用另一个公共代理服务器时,一切都正常工作
使用新代理服务器和try-catch的重构代码示例:
var searchResults = "http://google.com/search?q=" + textBox1.Text.Trim();
HttpWebResponse response = null;
var request = (HttpWebRequest)WebRequest.Create(searchResults);
request.Method = "GET";
request.Proxy = new WebProxy("http://92.46.122.98:3128", true);
try
{
response = (HttpWebResponse) request.GetResponse();
}
catch (Exception ex)
{
MessageBox.Show("Proxy server is probably do not working. Error message: "+ex.Message);
}
if (response != null)
{
MessageBox.Show("Job done!");
}