分享页面

C#语言代码示例

string targetUrl = "https://test.ipw.cn";
// 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing
string proxyIp = "您的代理IP";
string proxyPort = "端口号";
string authKey = "请改成您的Key";
string password = "请改成您的AuthPwd";

WebProxy proxy = new WebProxy(string.Format("{0}:{1}", proxyIp, proxyPort), true);
proxy.Credentials = new NetworkCredential(authKey, password);
ServicePointManager.Expect100Continue = false;

var request = WebRequest.Create(targetUrl) as HttpWebRequest;

request.AllowAutoRedirect = true;
request.KeepAlive = true;
request.Method    = "GET";
request.Proxy     = proxy;
request.Timeout     = 10000;
request.ServicePoint.ConnectionLimit = 16;

using (var resp = request.GetResponse() as HttpWebResponse)
using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)){
  string htmlStr = reader.ReadToEnd();
}
本文导读