Tuesday, March 15, 2011

WinINet: How to prevent HttpSendRequest to follow redirects (30x Status Codes)?

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.

From stackoverflow
  • I found a flag INTERNET_FLAG_NO_AUTO_REDIRECT that I must pass to HttpOpenRequest.

    But, it isn't working....

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

  • 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.

0 comments:

Post a Comment