C#语言代码示例
发布时间:2023-03-27 21:36
string targetUrl = "https://ip.cn/api/index?ip=&type=0";
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();
}
相关文章