C#语言代码示例
发布时间:2022-07-03 00:48
string targetUrl = "http://myip.ipip.net";
-
string proxyIp = "219.151.125.106";
string proxyPort = "31615";
string authKey = "895314XY";
string password = "24D6YB309ZCB";
-
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();
}
相关文章