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

//打开注册表键
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; //设置代理

posted @ 2011-05-12 10:50  拼博之路  阅读(508)  评论(0编辑  收藏  举报