帮助文档>代理IP>代码示例 > C#语言代码示例

C#语言代码示例

发布时间:2023-03-27 21:36
  1. string targetUrl = "https://ip.cn/api/index?ip=&type=0";
  2. string proxyIp = "您的代理IP";
  3. string proxyPort = "端口号";
  4. string authKey = "请改成您的Key";
  5. string password = "请改成您的AuthPwd";
  6. WebProxy proxy = new WebProxy(string.Format("{0}:{1}", proxyIp, proxyPort), true);
  7. proxy.Credentials = new NetworkCredential(authKey, password);
  8. ServicePointManager.Expect100Continue = false;
  9. var request = WebRequest.Create(targetUrl) as HttpWebRequest;
  10. request.AllowAutoRedirect = true;
  11. request.KeepAlive = true;
  12. request.Method = "GET";
  13. request.Proxy = proxy;
  14. request.Timeout = 10000;
  15. request.ServicePoint.ConnectionLimit = 16;
  16. using (var resp = request.GetResponse() as HttpWebResponse)
  17. using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)){
  18. string htmlStr = reader.ReadToEnd();
  19. }
本文导读

客户热线: