The default behavior of WinHttpRequest.5.1 is to automatically follow redirects, this can be a problem when you want to catch the headers of a response, before following a redirect. To change this behavior in AutoIt, you use the Option property of the WinHttpRequest.5.1 com object.
Note. If you disable auto-following, you will have to look for the location header on your own, and follow any redirects as needed.
Disable auto-following of redirects
Below is an example of how you can set your WinHttpRequest.5.1 com object in AutoIt, to not automatically follow redirects.
$oHTTP.Option(6) = false ; do not follow redirects automatically
The option needs to be set after creating the object, and before sending the request. A fully working example has been included below:
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "http://brugbart.com/", False) $oHTTP.Option(6) = false ; do not follow redirects automatically $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode == 200 then $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) FileClose($file) EndIf