WebClien使用国外代理服务器访问URL

using (WebClient wc = new WebClient())
 {

      //代理服务器的IP和Port
      WebProxy myProxy = new WebProxy(Common.server, Convert.ToInt32(Common.port));

      // 设置代理服务器用户帐号username,password
      myProxy.Credentials = new NetworkCredential(Common.user,Common.pwd);

      / 为WebClient设置proxy
      wc.Proxy = myProxy;

      //所要访问的URL的headers
      wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
      wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh - CN,zh; q = 0.9");
      wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
      wc.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
      wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla / 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 89.0.4389.114 Safari / 537.36");
      wc.Headers.Add(HttpRequestHeader.Pragma, "no-cache");

      //自己需要访问的URL
      string uri = Common.URL;

      byte[] bytes = wc.DownloadData(uri);
      Console.ReadKey()
}

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页