WebProxy proxyObject = new WebProxy(ip, port); //str为IP地址 port为端口号
proxyObject.BypassProxyOnLocal = true;
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://1111.ip138.com/ic.asp");
Req.UserAgent = "MSIE6.0";
Req.Method = "GET";
Req.AllowAutoRedirect = false;
Req.Timeout = 10000; //设定超时时间
if (ip != "127.0.0.1")
Req.Proxy = proxyObject; //设置代理
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();////////这里就报错了,远程服务器403错误,,怎么修改改一下啊?
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{}
不要设置代理,然后访问试试看。注释掉Req.Proxy = proxyObject; 这一行。
确实是可以,但是如果我没有这句怎么去判断代理IP是否可用