会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
我思考..我存在..
好好学习..天天向上.. 159753258 楼上我老婆,楼下是我! 呼叫中心、小型信息管理系统,电话:13516218837
博客园
首页
新随笔
联系
管理
订阅
webClient 利用代理连接Rss资源
在做ScreenSaver的StartKit时,RSS源总报无效。
看错误是 程服务器返回错误: (407) 需要代理身份验证
才明白原来是公司上网用的是代理:
怎么样给WebClient加上代理呢?
代码如下:
下载RSS资源
1
/**/
///
<summary>
2
///
根据一个指向有效的 RSS 2.0 XML 文件的 URI 构造 RSSFeed 对象的工厂。
3
///
</summary>
4
///
<exception cref="System.Net.WebException">
当无法在 Web 上找到该 URI 时引发。
</exception>
5
///
<param name="uri">
从该处读取 RSS 源的 URI。
</param>
6
public
static
RssFeed FromUri(
string
uri)
7
{
8
XmlDocument xmlDoc;
9
WebClient webClient
=
new
WebClient();
10
WebProxy webProxy
=
new
WebProxy(
"
192.168.0.3:8080
"
);
11
webProxy.Credentials
=
new
System.Net.NetworkCredential(
"username,"password")
webClient.Proxy
=
webProxy;
13
using
(Stream rssStream
=
webClient.OpenRead(uri))
14
{
15
TextReader textReader
=
new
StreamReader(rssStream);
16
XmlTextReader reader
=
new
XmlTextReader(textReader);
17
xmlDoc
=
new
XmlDocument();
18
xmlDoc.Load(reader);
19
}
20
return
new
RssFeed(xmlDoc);
21
}
posted @
2007-04-09 17:31
南守拥
阅读(
592
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告