C#语言使用隧道HTTP代码示例
string targetUrl = "http://httpbin.org/ip";
string proxyIp = "ip.hahado.cn";
string proxyPort = "10080";
string username = "username";
string password = "password";
WebProxy proxy = new WebProxy(string.Format("{0}:{1}", proxyIp, proxyPort), true);
proxy.Credentials = new NetworkCredential(username, 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();
}

这段代码展示了如何在C#中使用WebProxy通过指定的代理服务器进行HTTP GET请求。它配置了代理的用户名、密码,并设置了请求超时和连接限制。
1404

被折叠的 条评论
为什么被折叠?



