/// <summary>
/// 验证代理IP是否有效的方法
/// </summary>
/// <param name="IP"></param>
/// <param name="port"></param>
/// <returns></returns>
private String YanzhengIp(string IP,int port)
{
bool isok = true;
string rs =null;
while (isok)
{
try
{
//设置代理IP
WebProxy proxyObject = new WebProxy(IP, port);
//向指定地址发送请求
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
HttpWReq.Proxy = proxyObject;
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
//HttpWReq.Timeout = 10000;
StreamReader sr = new StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
string xmlContent = sr.ReadToEnd().Trim();
sr.Close();
HttpWResp.Close();
HttpWReq.Abort();
rs = xmlContent;
isok = false;
}
catch (Exception)
{
isok = false;
rs = "Error";
}
}
return rs;
}
/// 验证代理IP是否有效的方法
/// </summary>
/// <param name="IP"></param>
/// <param name="port"></param>
/// <returns></returns>
private String YanzhengIp(string IP,int port)
{
bool isok = true;
string rs =null;
while (isok)
{
try
{
//设置代理IP
WebProxy proxyObject = new WebProxy(IP, port);
//向指定地址发送请求
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
HttpWReq.Proxy = proxyObject;
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
//HttpWReq.Timeout = 10000;
StreamReader sr = new StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
string xmlContent = sr.ReadToEnd().Trim();
sr.Close();
HttpWResp.Close();
HttpWReq.Abort();
rs = xmlContent;
isok = false;
}
catch (Exception)
{
isok = false;
rs = "Error";
}
}
return rs;
}