分享页面

C#语言代码示例

发布时间:2022-06-21 09:23
  1. string targetUrl = "https://test.ipw.cn";
  2. // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing
  3. string proxyIp = "您的代理IP";
  4. string proxyPort = "端口号";
  5. string authKey = "请改成您的Key";
  6. string password = "请改成您的AuthPwd";
  7. WebProxy proxy = new WebProxy(string.Format("{0}:{1}", proxyIp, proxyPort), true);
  8. proxy.Credentials = new NetworkCredential(authKey, password);
  9. ServicePointManager.Expect100Continue = false;
  10. var request = WebRequest.Create(targetUrl) as HttpWebRequest;
  11. request.AllowAutoRedirect = true;
  12. request.KeepAlive = true;
  13. request.Method = "GET";
  14. request.Proxy = proxy;
  15. request.Timeout = 10000;
  16. request.ServicePoint.ConnectionLimit = 16;
  17. using (var resp = request.GetResponse() as HttpWebResponse)
  18. using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)){
  19. string htmlStr = reader.ReadToEnd();
  20. }
本文导读