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
}
}