3

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.

zett42
  • 25,437
  • 3
  • 35
  • 72
Ali Asadpoor
  • 327
  • 1
  • 13
  • You are propably referring to the example at [this page](https://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx). Look again at the code. The check for `ERROR_WINHTTP_RESEND_REQUEST` is done if either `WinHttpSendRequest()` or `WinHttpReceiveResponse()` fails. – zett42 Jul 26 '17 at 15:33

1 Answers1

4

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.

zett42
  • 25,437
  • 3
  • 35
  • 72