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

  当“使用自动配置脚本”不使用时,使用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. iOS案例:读取指定txt文件,并把文件中的内容输出出来

    用到的是NSString中的initWithContentsOfFile: encoding方法 // // main.m // 读取指定文件并输出内容 // // Created by Apple ...

  2. onclick事件分析

     有些时候,我们想实现这样的一种效果:      <a href="imgs/2.jpg" title="A fireworks display" onc ...

  3. [转载] 跟着实例学习zookeeper 的用法

    原文: http://ifeve.com/zookeeper-curato-framework/ zookeeper 的原生客户端库过于底层, 用户为了使用 zookeeper需要编写大量的代码, 为 ...

  4. nodejs学习笔记<五>npm使用

    NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题. 以下是几种常见使用场景: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器下载并 ...

  5. 64位WIN7+oracle11g+plsql安装

    64位WIN7+oracle11g+plsql安装   上部转自Oracle 11g R2 for Win7旗舰版(64位)的安装步骤 1.下载Oracle 11g R2 for Windows的版本 ...

  6. Java集合类源码分析

    常用类及源码分析 集合类 原理分析 Collection   List   Vector 扩充容量的方法 ensureCapacityHelper很多方法都加入了synchronized同步语句,来保 ...

  7. 企业信息化快速开发平台JeeSite

    网站:http://jeesite.com/ 可用于企业后台管理

  8. D3.js 第一个程序 HelloWorld

    一.HTML 是怎么输出 HelloWorld 的 <html> <head> <meta charset="utf-8"> <title ...

  9. JS 的子父级页面调用

    window.frames["iframevehquery"].add(); // 父页面调用嵌套子页面的js函数, iframevehquery 为 iframe 的name值, ...

  10. easyui 查询

    <fieldset> <legend>查询</legend> <table style="width: 100%;"> <tr ...