2

When I make an HTTP request with the method HttpSendRequest of the WinINet API, and the response sends "302: Moved Temporarily", the WinINet API automatically follows the redirection instruction and makes a new request.

So, How to prevent HttpSendRequest to follow redirects (30x Status Codes)?

I don't want't to make two requests... I wan't to get the the first response it got with the status code 302 in it's header.

Daniel Silveira
  • 41,125
  • 36
  • 100
  • 121

4 Answers4

2

I found a flag INTERNET_FLAG_NO_AUTO_REDIRECT that I must pass to HttpOpenRequest.

But, it isn't working....

Daniel Silveira
  • 41,125
  • 36
  • 100
  • 121
0

Seems like WinInet behavior largely depends of lpszAgent specified in the InternetOpen function call. When you pass "Mozilla/5.0 (compatible)" all redirects are ignored and you will get RAW HTML result when reading response with InternetReadFile.

On the other hand, if you need "redirected" output, you must specify your application name in the Agent argument, for example "ConEmu Update".

Maximus
  • 10,751
  • 8
  • 47
  • 65
0

Redirection can be prevented if you are able to use WinHTTP instead (link).

Community
  • 1
  • 1
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
0

Try using INTERNET_FLAG_NO_AUTO_REDIRECT in the call to HttpSendRequest. Sounds like you're trying to use it from HttpOpenRequest.

I use this flag with InternetOpenUrl, and it works properly in that call.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
  • 1
    I don't think this is the case. HttpSendRequest does not accept a dwFlags parameter, and the flag is mentioned on the HttpOpenRequest msdn page. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384233(v=vs.85).aspx – Derek Jun 19 '13 at 21:51