Jump to content
Sign in to follow this  
BetaTester69

Retrieve URL from HTTP Request result

Recommended Posts

BetaTester69

Hi all! 

First of all congratulation on the fantastic scripting program and great forum we have here.

I'm sick and tired of searching for a solution to my problem but cant seem to find it, maybe someone can point me a solution or a post with a solution.

This is my problem.

I make a GET to a website, and the website sends me to a random page of the website. I need to know what URL the website sent me to. I tried to look at the headers and the source of the page, but i didnt found any reference to final ÛRL i got sent to.

In this example, i use google.com that redirects me to my country's google page. in this example i know i can get it from the source, but imagine i cant get it. How could i get the random URL the website is giving me?

I DID use the search feature in this forum but got nowhere.

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "http://www.google.com/", False)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
$oHTTP.Send()
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
$HeaderResponses = $oHTTP.GetAllResponseHeaders()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $HeaderResponses = ' & $HeaderResponses & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

If $oStatusCode == 200 Then
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oStatusCode = ' & $oStatusCode & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    $file = FileOpen("ReceivedHTML.html", 2) ; The value of 2 overwrites the file if it already exists
    FileWrite($file, $oReceived)
    FileClose($file)
EndIf

Thanks in advance

Share this post


Link to post
Share on other sites
mikell

I can't see how to get this using winhttprequest but this gets the info you want

#include <IE.au3>

$oIE = _IECreate("http://www.google.com/", 0, 0)
Msgbox(0,"", $oIE.locationurl)
$oIE.Quit()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×