1. 程式人生 > >WinHTTP 自動代理支援

WinHTTP 自動代理支援

To ease the configuration of proxy settings, WinHTTP 5.1 implements the Web Proxy Auto-Discovery (WPAD) protocol, also known as autoproxy.

為簡化代理配置,WinHTTP 5.1實現了Web代理自動發現協議(WPAD),也叫autoproxy。

AutoProxy總覽

Applications and components that use WinHTTP to send HTTP requests should ensure that the proxy configuration is set correctly. Unless the client has a direct Internet connection, an HTTP request should normally be sent through a web proxy server that connects the client's local network to the Internet (for example, this is often the case for Web clients on a corporate LAN). For server-based applications, the proxy configuration is normally managed by the server's administrator using the WinHTTP ProxyCfg.exe utility. The server administrator knows the name of the proxy server in advance and uses ProxyCfg.exe to record this setting in the registry where WinHTTP can look it up. However, requiring client desktop end-users to manually configure WinHTTP proxy settings is problematic. The end-user may not know the name of the proxy server; requiring the end-user to run the ProxyCfg.exe utility can be a support burden for an organization. To support a good user experience, a web-enabled client application should determine the proxy configuration without user intervention.

使用WinHTTP的程式和元件傳送HTTP請求要保證代理設定正確。除非客戶是直連上網,HTTP請求都會發送給連線客戶和Internet的web代理(這在Web使用者和公司內網很常見)。對於基於伺服器的程式來說,代理設定通常由伺服器管理員使用WinHTTP的ProxyCfg.exe管理。管理員知道代理伺服器的名稱,並使用ProxyCfg.exe把這些設定記錄到登錄檔裡,以便WinHTTP找到它。然而要求客戶端的桌面終端使用者手動配置WinHTTP代理設定會產生很多問題。終端使用者有可能不知道代理伺服器名稱,讓使用者執行ProxyCfg.exe工具也是一個負擔很重的工作。要有好的使用者體驗,基於web的應用程式應該可以自動探測代理配置而不需要使用者干預。

To make configuring the proxy settings for WinHTTP-based applications easier, WinHTTP now implements theWeb Proxy Auto-Discovery (WPAD) protocol, often referred to asautoproxy. This is the same protocol that web browsers implement to automatically discover the proxy configuration without requiring an end-user to specify a proxy server manually. This feature is available starting with WinHTTP version 5.1 in Windows 2000 Service Pack 3, Windows XP Service Pack 1 and Windows Server 2003. Note that although both Microsoft Internet Explorer and Microsoft WinHTTP support WPAD, the specification never progressed beyond the "Internet-Draft" stage, and expired in May 2001.

為了使基於WinHTTP的程式使用代理更簡單,WinHTTP實現了Web Proxy Auto-Discovery (WPAD) 協議,也常被稱為autoproxy。瀏覽器也實現了同樣的無需使用者干預的代理髮現功能。這個功能從WinHTTP5.1開始實現,預設的在2000 SP3 、XP SP1以及Server 2003及以後作業系統都實現了上述功能。

The WPAD protocol works as follows:

WPAD協議按以下方式工作:

  1. Using the DHCP and/or DNS network protocols, the URL of a Proxy Auto-Configuration (PAC) file is discovered. The URL identifies a PAC file on the client's local network. WinHTTP supports only "http:" and "https:" PAC URLs; it does not, for example, support "file:" URLS.
  2. 使用DHCP和/或DNS網路協議,發現一個標識代理自動配置檔案的URL.這個URL在使用者本地網路發現一個PAC檔案,WinHTTP只支援形如"http:" 和"https:"的 PAC URLs。
  3. The PAC file is downloaded and optionally cached on the client's computer. The PAC file is an executable script that generates a list of one or more proxy servers given a target host name and URL. WinHTTP supports only ECMAScript-based PAC files.
  4. PAC檔案下載並根據選項是否儲存在使用者計算機本地。這個PAC檔案是一個可執行的指令碼,這個指令碼產生一個列表,這個列表中有一個或多個以URL或主機名出現的代理伺服器。WinHTTP只支援ECMA指令碼PAC檔案。                                                                                     
  5. On each HTTP request, the PAC script code is executed, with the host name and URL of the HTTP request passed in as parameters. WinHTTP expects the PAC script code to contain a function calledFindProxyForURL, in the form:
  6. 對每個HTTP請求,PAC指令碼程式碼都執行,使用HTTP請求URL或主機名作為引數。WinHTTP要求PAC指令碼包含一個叫FindProxyForURL函式,
  7. FindProxyForURL( url, host ); 
    
  8. This function computes a list of one or more proxy servers that can be used by the HTTP client in order to transmit the request. If the PAC script determines that the HTTP client can reach the target server directly without going through a proxy server at all, it indicates this using a special return value.
  9. 這個函式計算一個列表,這個列表中包含一個或多個代理伺服器,HTTP客戶端使用這些伺服器轉發請求。如果PAC指令碼探測到HTTP客戶端可以不使用代理直接訪問網路,就會返回一個特定的值。

AutoProxy Topics