WinInet call HttpSendRequest doesn't pass auth information next time when I call it with the same connection handle

StackOverflow https://stackoverflow.com/questions/14719215

  •  06-03-2022
  •  | 
  •  

Question

I'm confused by the following problem I experience. We use Windows 2008 R2 machine with IE 8.0 installed. Next I try programmatically to connect to a server with InternetConnect call(auth credentials are provided as an arguments passed to it). It succeeds. Next I call HttpOpenRequest and HttpSendRequest. The calls to HttpOpenRequest and HttpSendRequest are performed using the same connection handle InternetConnect call returned. At some certain point of time HttpSendRequest begins to fail. From traffic capture I see there is auth info missing and it makes server in its turn to return 401 result. InternetSetOption call with INTERNET_OPTION_USERNAME and INTERNET_OPTION_PASSWORD provided doesn't take any effect. After HttpSendRequest fails I call GetLastError and receive at first ERROR_HTTP_INVALID_SERVER_RESPONSE and at second ERROR_INTERNET_INCORRECT_HANDLE_STATE if I try to re-send my request with HttpSendRequest.

Maybe somebody of you experienced similar problem?

Was it helpful?

Solution

I discovered it's a normal way of how client behaves. First it tries to contact resource anonymously and then if it fails it tries to use credentials. Within single function call it's ok to have one 401 result because the very next request comes along with auth credentials.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top