C# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用
2011-07-24 10:05
761 查看
相信大家都使用过代理IP上过网,但是有的IP一两天就失效了。要一个一个的手工去试打开IE,关闭IE,多烦啊。
有了这篇文章就好了。我们可以使用HttpWebRequest,HttpWebResponse 来代理验证,谢谢大家评论指导!
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!我不说了大家自己看
public void yanzhen(string str, int port)
{
WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com.tw/");
Req.Proxy = proxyObject; //设置代理
//转载请标明来自 问题解决园http://wenti.cnblogs.com/
//文章地址
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
string str = "";
string OkStr = "";
Encoding code = Encoding.GetEncoding("UTF-8");
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{
if (sr != null)
{
try
{
str = sr.ReadToEnd();
StringSub.substr(str, "<h2>", "</h2>", 0);
str = str.Substring(str.IndexOf(start) + start.Length);
OkStr = str.Substring(0, str.IndexOf(last));
MessageBox.Show("验证成功!显示IP为" + OkStr);
}
catch
{
MessageBox.Show("文件读取失败!");
}
finally
{
sr.Close();
}
}
}
}
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!
有了这篇文章就好了。我们可以使用HttpWebRequest,HttpWebResponse 来代理验证,谢谢大家评论指导!
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!我不说了大家自己看
public void yanzhen(string str, int port)
{
WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com.tw/");
Req.Proxy = proxyObject; //设置代理
//转载请标明来自 问题解决园http://wenti.cnblogs.com/
//文章地址
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
string str = "";
string OkStr = "";
Encoding code = Encoding.GetEncoding("UTF-8");
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{
if (sr != null)
{
try
{
str = sr.ReadToEnd();
StringSub.substr(str, "<h2>", "</h2>", 0);
str = str.Substring(str.IndexOf(start) + start.Length);
OkStr = str.Substring(0, str.IndexOf(last));
MessageBox.Show("验证成功!显示IP为" + OkStr);
}
catch
{
MessageBox.Show("文件读取失败!");
}
finally
{
sr.Close();
}
}
}
}
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!
相关文章推荐
- c#使用HttpWebRequest,HttpWebResponse快速验证代理IP是否有用
- c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用
- c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用
- c# 快速验证代理IP是否有用
- c# 快速验证代理IP是否有用
- c# 快速验证代理IP是否有用
- c# 快速验证代理IP是否有用
- c# 快速验证代理IP是否有用
- 解决httpwebrequest无法通过使用代理的局域网获取response的问题
- c#中HttpWebRequest使用Proxy实现指定IP的域名请求
- C#中HttpWebRequest与HttpWebResponse的使用方法
- C#使用HttpWebRequest和HttpWebResponse上传文件示例
- C#中HttpWebrequest使用需要认证的代理
- 【原创】C#使用HttpWebRequest,HttpWebResponse
- C#中HttpWebRequest与HttpWebResponse的使用方法
- 浅谈C#中HttpWebRequest与HttpWebResponse的使用方法
- C#中网页文件下载——HttpWebRequest与HttpWebResponse的使用方法
- C#中HttpWebRequest与HttpWebResponse的使用方法
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
- HttpWebRequest使用有身份验证的代理