沙漠中的鱼

欲上天堂,先下地狱
posts - 0, comments - 56, trackbacks - 0, articles - 119
  BlogJava :: 首页 ::  :: 联系 :: 聚合  :: 管理

C#设置IE代理和使用代理访问网页

Posted on 2009-06-10 22:50 沙漠中的鱼 阅读(1932) 评论(0)  编辑  收藏 所属分类: 其他

//打开注册表键
Microsoft.Win32.RegistryKey rk=Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings",true);

//设置代理可用
rk.SetValue("ProxyEnable",1);
//设置代理IP和端口
rk.SetValue("ProxyServer","222.222.222.222:808");
rk.Close();

 

使用WebProxy类,该类空间名 using  System.net;
  
WebProxy proxyObject = new WebProxy("代理服务器IP和端口(例如:http://proxyserver:80/)",true);
WebRequest req = WebRequest.Create("http://www.contoso.com"); //使用WebRequest上网
req.Proxy = proxyObject; //设置代理


只有注册用户登录后才能发表评论。


网站导航: