Export (0) Print
Expand All

WinHttpSetDefaultProxyConfiguration function

The WinHttpSetDefaultProxyConfiguration function sets the default WinHTTP proxy configuration in the registry.

Syntax


BOOL WINAPI WinHttpSetDefaultProxyConfiguration(
  _In_  WINHTTP_PROXY_INFO *pProxyInfo
);

Parameters

pProxyInfo [in]

A pointer to a variable of type WINHTTP_PROXY_INFO that specifies the default proxy configuration.

Return value

Returns TRUE if successful, or FALSE otherwise. For extended error information, call GetLastError. Among the error codes returned are the following.

Error CodeDescription
ERROR_WINHTTP_INTERNAL_ERROR

An internal error has occurred.

ERROR_NOT_ENOUGH_MEMORY

Not enough memory was available to complete the requested operation. (Windows error code)

 

Remarks

WinHttpSetDefaultProxyConfiguration changes the proxy configuration set by ProxyCfg.exe.

The default proxy configuration set by this function can be overridden for an existing WinHTTP session by calling WinHttpSetOption and specifying the WINHTTP_OPTION_PROXY flag. The default proxy configuration can be overridden for a new session by specifying the configuration with the WinHttpOpen function.

The dwAccessType member of the WINHTTP_PROXY_INFO structure pointed to by pProxyInfo should be set to WINHTTP_ACCESS_TYPE_NAMED_PROXY if a proxy is specified. Otherwise, it should be set to WINHTTP_ACCESS_TYPE_DEFAULT_PROXY.

Any new sessions created after calling this function use the new default proxy configuration.

Even when WinHTTP is used in asynchronous mode (that is, when WINHTTP_FLAG_ASYNC has been set in WinHttpOpen), this function operates synchronously. The return value indicates success or failure. To get extended error information, call GetLastError.

Note  For Windows XP and Windows 2000, see the Run-Time Requirements section of the WinHTTP start page.

Examples

The following code example shows how to set the default proxy configuration in the registry.


    WINHTTP_PROXY_INFO proxyInfo;

    // Allocate memory for string members.
    proxyInfo.lpszProxy = new WCHAR[25];
    proxyInfo.lpszProxyBypass = new WCHAR[25];
    
    // Set the members of the proxy info structure.
    proxyInfo.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
    swprintf_s(proxyInfo.lpszProxy, 25, L"proxy_server");
    swprintf_s(proxyInfo.lpszProxyBypass, 25, L"<local>");

    // Set the default proxy configuration.
    if (WinHttpSetDefaultProxyConfiguration( &proxyInfo ))
        printf("Proxy Configuration Set.\n");

    // Free memory allocated to the strings.
    delete [] proxyInfo.lpszProxy;
    delete [] proxyInfo.lpszProxyBypass;


Requirements

Minimum supported client

Windows XP, Windows 2000 Professional with SP3 [desktop apps only]

Minimum supported server

Windows Server 2003, Windows 2000 Server with SP3 [desktop apps only]

Redistributable

WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000.

Header

Winhttp.h

Library

Winhttp.lib

DLL

Winhttp.dll

See also

ProxyCfg.exe, a Proxy Configuration Tool
WinHttpGetDefaultProxyConfiguration
WinHTTP Versions

 

 

Community Additions

ADD
Show:
© 2014 Microsoft