ideacore

在很多时候我们需要用到IP代理,比如爬虫、投票等

封IP是一种很常用的办法,所谓道高一尺、魔高一丈,IP代理应运而生

最简单的一段代码

        static void Main(string[] args)
        {
            var httpRequest = (HttpWebRequest)WebRequest.Create("http://1212.ip138.com/ic.asp");
            httpRequest.Method = "GET";
            httpRequest.Credentials = CredentialCache.DefaultCredentials;
            // 设置代理属性WebProxy -------------------------------------------------
            var proxy = new WebProxy {Address = new Uri("http://59.62.112.203:808/")};
            //proxy.Credentials = new NetworkCredential("xxx", "xxx");
            // 在发起HTTP请求前将proxy赋值给HttpWebRequest的Proxy 属性
            httpRequest.Proxy = proxy;
            //-------------------------------------------------
            var res = (HttpWebResponse)httpRequest.GetResponse();
            var reader = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("GB2312"));
            var content = reader.ReadToEnd();
            reader.Close();
            Console.WriteLine(content);
            Console.Read();
        }

这样看来,其实使用代理也很简单,网络上有很多公开的代理IP地址,比如在这里:http://www.xicidaili.com/

分类:

技术点:

相关文章:

  • 2021-12-06
  • 2022-01-02
  • 2021-08-05
  • 2021-12-04
  • 2021-05-27
  • 2021-11-03
  • 2021-12-12
  • 2022-01-12
猜你喜欢
  • 2021-11-01
  • 2022-01-06
  • 2021-11-01
  • 2021-08-04
  • 2021-08-26
  • 2021-04-18
  • 2021-06-17
相关资源
相似解决方案