C#如何實現IE代理設置?
IE的代理設置存放在注冊表中,位置為:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
ProxyEnable 代理是否啟用,
ProxyServer 代理服務器
操作注冊表的類是:Microsoft.Win32.RegistryKey
ProxyEnable 代理是否啟用,
ProxyServer 代理服務器
操作注冊表的類是:Microsoft.Win32.RegistryKey
public static void ProxySetting(WebRequest request)
{
WebProxy proxy = WebProxy.GetDefaultProxy();//獲取IE缺省設置
//如果缺省設置為空,則有可能是根本不需要代理服務器,如果此時配置文件中也未配置則認為不需Proxy
if (proxy.Address == null)
proxy.Address = new Uri("××××××:8080");//按配置文件創建Proxy 地置
if (proxy.Address != null)//如果地址為空,則不需要代理服務器
{
proxy.Credentials = new NetworkCredential("test123","123456");//從配置封裝參數中創建
request.Proxy = proxy;//賦予 request.Proxy
}
}
{
WebProxy proxy = WebProxy.GetDefaultProxy();//獲取IE缺省設置
//如果缺省設置為空,則有可能是根本不需要代理服務器,如果此時配置文件中也未配置則認為不需Proxy
if (proxy.Address == null)
proxy.Address = new Uri("××××××:8080");//按配置文件創建Proxy 地置
if (proxy.Address != null)//如果地址為空,則不需要代理服務器
{
proxy.Credentials = new NetworkCredential("test123","123456");//從配置封裝參數中創建
request.Proxy = proxy;//賦予 request.Proxy
}
}