c# 快速验证代理IP是否有用

 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; //设置代理
            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();
                    }
                }
            }
        }

上一篇:利用Python网络爬虫采集天气网的实时信息—BeautifulSoup选择器


下一篇:探究Entity Framework如何在多个仓储层实例之间工作单元的实现及原理(2018-05-31修改部分严重错误代码)