C#代理请求-示例代码

发布时间:2025-12-07 17:49:15  阅读:33

WebProxy proxyObject = new WebProxy(str, port);
//str为IP地址 port为端口号 代理类
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.xxxx.com"); 
// 访问这个网站 ,返回的就是你发出请求的代理ip 这个做代理ip测试非常方便,可以知道代理是否成功

Req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQWubi 133; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; CIBA; InfoPath.2)";
Req.Proxy = proxyObject; //设置代理
Req.Method = "GET";
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
string StringSub = "";
string OkStr = "";
Encoding code = Encoding.GetEncoding("UTF-8");
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{

    str = sr.ReadToEnd();
    //获取得到的网址html返回数据,这里就可以使用某些解析html的dll直接使用了,比如htmlpaser

}
免费试用

客服

在线客服:

:584170010

:18328351249

:service@wukongdaili.com

售后客服

技术客服