The WinHttpSetCredentials function passes the required authorization credentials to the server.
BOOLAPI WinHttpSetCredentials( IN HINTERNET hRequest, IN DWORD AuthTargets, IN DWORD AuthScheme, IN LPCWSTR pwszUserName, IN LPCWSTR pwszPassword, IN LPVOID pAuthParams );
An unsigned integer that specifies a flag that contains the authentication target. Can be one of the values in the following table.
||Credentials are passed to a server.|
||Credentials are passed to a proxy.|
An unsigned integer that specifies a flag that contains the authentication scheme. Must be one of the supported authentication schemes returned from WinHttpQueryAuthSchemes. The following table identifies the possible values.
Pointer to a string that contains a valid user name.
Pointer to a string that contains a valid password. The password can be blank.
This parameter is reserved and must be NULL.
Returns TRUE if successful, or FALSE otherwise. For extended error information, call GetLastError. The following table identifies the error codes returned.
||The requested operation cannot be carried out because the handle supplied is not in the correct state.|
||The type of handle supplied is incorrect for this operation.|
||An internal error has occurred.|
||Not enough memory was available to complete the requested operation (Windows error code).|
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.
The credentials set by WinHttpSetCredentials are only used for a single request; WinHTTP does not cache these credentials for use in subsequent requests. As a result, applications must be written so that they can respond to multiple challenges. If an authenticated connection is re-used, subsequent requests cannot be challenged, but your code should be able to respond to a challenge at any point.
For sample code that illustrates the use of WinHttpSetCredentials, see Authentication in WinHTTP.
|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.|