webClient 利用代理连接Rss资源

在做ScreenSaver的StartKit时,RSS源总报无效。
看错误是 程服务器返回错误: (407) 需要代理身份验证
才明白原来是公司上网用的是代理:
怎么样给WebClient加上代理呢?
代码如下:
ContractedBlock.gifExpandedBlockStart.gif下载RSS资源
 1ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>
 2InBlock.gif        /// 根据一个指向有效的 RSS 2.0 XML 文件的 URI 构造 RSSFeed 对象的工厂。
 3InBlock.gif        /// </summary>
 4InBlock.gif        /// <exception cref="System.Net.WebException">当无法在 Web 上找到该 URI 时引发。</exception>
 5ExpandedBlockEnd.gif        /// <param name="uri">从该处读取 RSS 源的 URI。</param>

 6None.gif        public static RssFeed FromUri(string uri)
 7ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 8InBlock.gif            XmlDocument xmlDoc;
 9InBlock.gif            WebClient webClient = new WebClient();
10InBlock.gif            WebProxy webProxy = new WebProxy("192.168.0.3:8080");
11InBlock.gif            webProxy.Credentials = new System.Net.NetworkCredential("username,"password")
InBlock.gif      webClient.Proxy = webProxy;
13InBlock.gif            using (Stream rssStream = webClient.OpenRead(uri))
14ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
15InBlock.gif                TextReader textReader = new StreamReader(rssStream);
16InBlock.gif                XmlTextReader reader = new XmlTextReader(textReader);
17InBlock.gif                xmlDoc = new XmlDocument();
18InBlock.gif                xmlDoc.Load(reader);
19ExpandedSubBlockEnd.gif            }

20InBlock.gif            return new RssFeed(xmlDoc);
21ExpandedBlockEnd.gif        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值