I’m programming with WinInet functions in C++ but I came across a problem.
My program opens an URL with HttpOpenRequest(), HttpSendRequest(), InternetReadFile()… functions and saves output data. I need to save URL with the output data, but in some cases server gives me 301 Moved and InternetReadFile() reads file from the new address.
This is Ok, but I need to find out what address it is. I tried to use HttpQueryInfo with HTTP_QUERY_RAW_HEADERS_CRLF but I didn’t obtain this info, only Content-Type, Cache-Control, Cookies, etc. When I use HTTP_QUERY_CONTENT_LOCATION or something similar I get ERROR_HTTP_HEADER_NOT_FOUND.
Can you help me?
After WinInet receives a Redirect response, by default it sends a new HTTP request to the new URL automatically. By the time WinInet is ready for you to start reading file data with
InternetReadFile(), the headers that are available at that time belong to the last URL requested, which may not be the same URL that you originally requested. That is why you are not seeing see aLocationheader. To process the headers for a Redirect response, you have to specify theINTERNET_FLAG_NO_AUTO_REDIRECTflag when callingHttpOpenRequest(), then you can useHttpQueryInfo()to detect a redirect status code and read itsLocationheader before then callingHttpSendRequest()to request the new URL being redirected to.