After a WinHTTP request receives 407, use WinHttpQueryAuthSchemes to inspect the offered methods and select one supported by the client and account. Set the credentials on that request:

WinHttpSetCredentials(
    requestHandle,
    WINHTTP_AUTH_TARGET_PROXY,
    selectedScheme,
    proxyUser,
    proxyPassword,
    nullptr);

The final reserved argument must be null. Check the Boolean result and GetLastError on failure. Success means the API accepted the setting, not that the proxy accepted the login.

Resend through a controlled authentication flow and inspect the response. Bound retries; a consumed request-body stream must be replayable if the operation is repeated. A destination 401 uses WINHTTP_AUTH_TARGET_SERVER, distinct from this proxy target.

These credentials apply to a single request. WinHTTP does not make them a general credential store for later requests. Reused authenticated connections can hide another challenge temporarily, so the application must still handle future challenges.

Keep proxy selection separate. A credential-bearing address string does not replace this request-handle API, just as successfully reaching the endpoint does not complete authentication.

Tënë sô zo