WinHttpSendRequest and ERROR_WINHTTP_RESEND_REQUEST

1.5k Views Asked by At

Is it possible for GetLastError() to return ERROR_WINHTTP_RESEND_REQUEST after calling WinHttpSendRequest?

Documentation for WinHttpSendRequest:

ERROR_WINHTTP_RESEND_REQUEST
The application must call WinHttpSendRequest again due to a redirect or authentication challenge. Windows Server 2003 with SP1, Windows XP with SP2 and Windows 2000:  This error is not supported.

But samples from MSDN (Authentication in WinHTTP) checks for this value after WinHttpReceiveResponse.

1

There are 1 best solutions below

0
zett42 On BEST ANSWER

But samples from MSDN (Authentication in WinHTTP) checks for this value after WinHttpReceiveResponse.

At a first glance the sample may look like that. But if you look closely, the sample actually checks for ERROR_WINHTTP_RESEND_REQUEST if either WinHttpSendRequest() or WinHttpReceiveResponse() fails:

// Send a request.
bResults = WinHttpSendRequest( hRequest,
                               WINHTTP_NO_ADDITIONAL_HEADERS,
                               0,
                               WINHTTP_NO_REQUEST_DATA,
                               0, 
                               0, 
                               0 );

// End the request.
if( bResults )
  bResults = WinHttpReceiveResponse( hRequest, NULL );

// Resend the request in case of 
// ERROR_WINHTTP_RESEND_REQUEST error.
if( !bResults && GetLastError( ) == ERROR_WINHTTP_RESEND_REQUEST)
    continue;

If WinHttpSendRequest() returns FALSE, the call to WinHttpReceiveResponse() will be skipped and GetLastError() will be checked for ERROR_WINHTTP_RESEND_REQUEST. This code is inside a while loop, so the continue statement will cause the remaining portion of the loop to be skipped so WinHttpSendRequest() will be called again.

Conclusion: The sample is in line with the reference documentation.