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

C#语言代码示例

发布时间:2022-07-03 00:48
  1. string targetUrl = "http://myip.ipip.net";
  2.  
  3. string proxyIp = "219.151.125.106";
  4. string proxyPort = "31615";
  5. string authKey = "895314XY";
  6. string password = "24D6YB309ZCB";
  7.  
  8. WebProxy proxy = new WebProxy(string.Format("{0}:{1}", proxyIp, proxyPort), true);
  9. proxy.Credentials = new NetworkCredential(authKey, password);
  10. ServicePointManager.Expect100Continue = false;
  11.  
  12. var request = WebRequest.Create(targetUrl) as HttpWebRequest;
  13.  
  14. request.AllowAutoRedirect = true;
  15. request.KeepAlive = true;
  16. request.Method = "GET";
  17. request.Proxy = proxy;
  18. request.Timeout = 10000;
  19. request.ServicePoint.ConnectionLimit = 16;
  20.  
  21. using (var resp = request.GetResponse() as HttpWebResponse)
  22. using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)){
  23. string htmlStr = reader.ReadToEnd();
  24. }
本文导读