首页 新闻 赞助 找找看

C#如何使用代理读取远程网页

0
悬赏园豆:5 [已解决问题] 解决于 2010-09-07 11:21

公司的网络是通过代理上网的.用WebClient MyWebClient = new WebClient();远程获取网页时,提示:"未能解析代理名: 'xxxx'". 这样程序出错了,就获取不了网页.

请大虾们帮忙

bicabo的主页 bicabo | 初学一级 | 园豆:160
提问于:2010-09-01 10:45
< >
分享
最佳答案
0

WebClient client = new WebClient();
client.Headers.Add(
"user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
client.Proxy
= new WebProxy("http://proxyserver:80/", true);
Stream data
= client.OpenRead("请求页面地址");
StreamReader reader
= new StreamReader(data);
string s = reader.ReadToEnd();
Console.WriteLine(s);
data.Close();
reader.Close();

 

收获园豆:5
慧☆星 | 大侠五级 |园豆:5640 | 2010-09-01 13:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册