This sample demonstrates how to use the WinHTTP API core functionality for querying the proxy settings to determine the proxy for a particular URL.
- WinHttpGetProxyForUrl
- DetectAutoProxyUrl
Both WinHttpGetProxyForUrl and WinHttpGetProxyForUrlEx are used in this sample. These functions implement the Web Proxy Auto-Discovery (WPAD) protocol for automatically configuring the proxy settings for an HTTP request. The WPAD protocol downloads a Proxy Auto-Configuration (PAC) file, which is a script that identifies the proxy server to use for a given target URL. PAC files are typically deployed by the IT department within a corporate network environment. These functions can automatically discover the location of the PAC file on the local network.
This sample can be extended as needed for your application, using the proxy code from this sample as a starting point, to add additional functionality. For example, an application could add a per-URL proxy cache, awareness for network changes, a filter for bad proxies, or other desired functionality.
Windows HTTP Services (WinHTTP)
To build the sample using Visual Studio:
- Open Windows Explorer and navigate to the \cpp directory.
- Double-click the icon for the WinhttpProxyStatus.sln file to open the file in Visual Studio.
- In the Build menu, select Build Solution. The application will be built in the default \Debug or \Release directory.
To run the sample:
- Navigate to the directory that contains the new executable, using the command prompt.
- Type WinhttpProxyStatus.exe <url> at the command prompt.