Posted on 2009-06-10 22:50
沙漠中的魚 閱讀(1964)
評論(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; //設置代理