“局域网设置”里有自动配置、代理服务器的设置项目,在进行网络通讯相关的开发时,需要使用到它们,下边介绍如何将这些设置信息读取出来。

  当“使用自动配置脚本”不使用时,使用WinHttpGetIEProxyConfigForCurrentUser函数来获取用户的代理配置。如果发现用户使用了自动配置脚本,那么就需要使用API
WinHttpGetProxyForUrl去获取某个url对应的代理。获取到代理之后需要考虑:1、是否需要拆分http、https、ftp、socks;2、hostname是否在“例外”中,需要考虑bypass有"<local>"的处理。

补充:使用自动配置脚本(也就是使用PAC文件)注意:1、IE设置里的pac文件路径不能是本地磁盘路径,否则WinHttpGetProxyForUrl函数无法正确执行;2、WinHttpGetProxyForUrl的第二个参数必须是http/https开头的完整路径。

  核心API就仅仅是WinHttpGetIEProxyConfigForCurrentUser和WinHttpGetProxyForUrl,可以在chromium中搜索这两关键函数获取chromium的实现代码。

  我使用的部分代码:

std::wstring CIEProxy::GetIEProxy( const std::wstring& strURL, const E_proxy_type& eProxyType )
{
std::wstring strRet_cswuyg;
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = {};
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = {};
BOOL bAutoDetect = FALSE; //“自动检测设置”,但有时候即便选择上也会返回0,所以需要根据url判断
if(::WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig))
{
if(ieProxyConfig.fAutoDetect)
{
bAutoDetect = TRUE;
}
if( ieProxyConfig.lpszAutoConfigUrl != NULL )
{
bAutoDetect = TRUE;
autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl;
}
}
else
{
// error
return strRet_cswuyg;
} if(bAutoDetect)
{
if (autoProxyOptions.lpszAutoConfigUrl != NULL)
{
autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL;
}
else
{
autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A;
}
autoProxyOptions.fAutoLogonIfChallenged = TRUE;
HINTERNET hSession = ::WinHttpOpen(, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC);
if (hSession != NULL)
{
WINHTTP_PROXY_INFO autoProxyInfo = {};
bAutoDetect = ::WinHttpGetProxyForUrl(hSession, strURL.c_str(), &autoProxyOptions, &autoProxyInfo);
if (hSession!= NULL)
{
::WinHttpCloseHandle(hSession);
}
if(autoProxyInfo.lpszProxy)
{
if (autoProxyInfo.lpszProxyBypass == NULL || CheckPassBy(strURL, autoProxyInfo.lpszProxyBypass))
{
std::wstring strProxyAddr = autoProxyInfo.lpszProxy;
strRet_cswuyg = GetProxyFromString(eProxyType, strProxyAddr);
}
if(autoProxyInfo.lpszProxy != NULL)
{
GlobalFree(autoProxyInfo.lpszProxy);
}
if(autoProxyInfo.lpszProxyBypass !=NULL)
{
GlobalFree(autoProxyInfo.lpszProxyBypass);
}
}
}
}
else
{
if(ieProxyConfig.lpszProxy != NULL)
{
if(ieProxyConfig.lpszProxyBypass == NULL || CheckPassBy(strURL, ieProxyConfig.lpszProxyBypass))
{
std::wstring strProxyAddr = ieProxyConfig.lpszProxy;
strRet_cswuyg = GetProxyFromString(eProxyType, strProxyAddr);
}
}
} if(ieProxyConfig.lpszAutoConfigUrl != NULL)
{
::GlobalFree(ieProxyConfig.lpszAutoConfigUrl);
}
if(ieProxyConfig.lpszProxy != NULL)
{
::GlobalFree(ieProxyConfig.lpszProxy);
}
if(ieProxyConfig.lpszProxyBypass != NULL)
{
::GlobalFree(ieProxyConfig.lpszProxyBypass);
} return strRet_cswuyg;
}

  插入:WinHTTP部分,WinHttpGetDefaultProxyConfiguration 用于从注册表获取WinHTTP的代理设置。这个代理设置是通过WinHttpSetDefaultProxyConfiguration或者ProxyCfg.exe设置的。跟IE代理不同。

参考:

1、chromium源码:

chromium/src/net/proxy/proxy_resolver_winhttp.cc

chromium/src/net/proxy/proxy_config.cc

chromium/src/net/proxy/proxy_bypass_rules.h

2、MSDN:

3、零碎资源:

http://stackoverflow.com/questions/202547/how-do-i-find-out-the-browsers-proxy-settings

http://www.cnblogs.com/chang290/archive/2013/01/12/2857426.html

获取IE代理服务器信息的更多相关文章

  1. sql 2012中获取表的信息,包含字段的描述

    1.获取数据库中的表 select name from sysobjects where type='U' 2.获取表字段(此处是Route表) Select name from syscolumns ...

  2. ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,

    一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...

  3. 获取应用程序信息.h

    ////  获取应用程序信息.h//  IOS笔记// 一般会用来判断是否有新版本.是否需要强制更新 iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中ta ...

  4. PHP获取当前服务器信息的基本语句

    下面是PHP获取当前服务器信息的基本语句. PHP程式版本: <?PHP echo PHP_VERSION; ?> ZEND版本: <?PHP echo zend_version() ...

  5. C# 获取 mp3文件信息

    C# 获取 mp3文件信息[包括:文件大小.歌曲长度.歌手.专辑] 第一种方式:[代码已验证] // http://bbs.csdn.net/topics/390392612   string fil ...

  6. Linux sysinfo获取系统相关信息

    Linux中,可以用sysinfo来获取系统相关信息. #include <stdio.h> #include <stdlib.h> #include <errno.h& ...

  7. android播放器如何获取音乐文件信息

    转http://blog.csdn.net/hellofeiya/article/details/8464356, android自带的音乐播放器中,在获取音乐文件信息的时候是通过扫描得到相关信息的. ...

  8. [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论

    前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...

  9. andriod 获取电池的信息

    <?xml version="1.0"?> <LinearLayout android:orientation="vertical" andr ...

随机推荐

  1. bzoj 1588: [HNOI2002]营业额统计 treap

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 13902  Solved: 5225[Submit][Sta ...

  2. 转 基于Quick-cocos2dx 2.2.3 的动态更新实现完整篇。(打包,服务器接口,模块自更新

    1,如何设计更新服务器接口. 2,不改变原框架的代码的情况下如何实现更新,并且可以实现精确的进度. 3,如何按照版本打包. 4,如何跨n个小版本更新. 5,版本回滚. 6,如何更新你的自动更新模块和f ...

  3. php提高程序效率的24个小技巧

    本文转自<php必须知道的300个问题>一书,在此记录方便以后查看 (1)用单引号代替双引号来包含字符串,这样做会更快些.因为php会在双引号包围的字符串中搜寻变量,单引号则不会.注意:只 ...

  4. Linux_常用命令_04_挂载

    1. mount [-t vfstype] [-o options] device dir ZC: -o 后面跟多个option的话,用逗号隔开.(例如:"mount -o rw,remou ...

  5. [转载] 深入 nginx 架构

    原文: http://www.cnbeta.com/articles/402709.htm 了解 nginx 架构帮助我们学习如何开发高性能 web 服务. 为了更好地理解设计,你需要了解NGINX是 ...

  6. mysql 大数据量的处理

    insert 1.过滤一段时间内重复的数据2.数据缓存起来,批量写入 select1.使用分区表2.主主复制,连接不同的mysql3.建立索引4.定时求平均值,写入一个新的表中

  7. Jump Game II

    Description: Given an array of non-negative integers, you are initially positioned at the first inde ...

  8. 在beforeAction里redirect无效,Yii2.0.8

    我是在官方GitHub上得到回答,试了一下,确实解决问题了.之前的问题描述: 之前是2.0.3,然后用composer直接升级到2.0.8,就不正常了,以为是我代码的问题,于是再次尝试 用compos ...

  9. SDL2.0的SDL_Event事件处理

    SDL_Event事件集合 SDL_AudioDeviceEvent SDL_ControllerAxisEvent SDL_ControllerButtonEvent SDL_ControllerD ...

  10. Webdriver - Selenium Grid Configuration

    Grid parameter: role = <hub|node> (default is no grid, just run an RC/webdriver server). When ...