I may be wrong, but I believe that roUrlTransfer automatically handles HTTP redirects (302). The underlying cUrl library should take care of that for you. There shouldn't be any need to read the headers yourself and send off another request for the redirected url.
In the first code you posted, you called AsyncGetToFile immediately followed by a call to AsyncHead, so you're issuing two simultaneous asynchronous requests to the same url, one for the whole file and one for just the headers. If the AsyncHead request completes first, your loop terminates before the AsyncGetToFile request completes, so you have no way of knowing whether the AsyncGetToFile call completed successfully.
In the last code you posted, if you get a 403 error that means that your access to that resource is forbidden; you won't be able to read it due to some security violation.
I would use something like this to do what you're trying to do:
Function getImageToFile(url As String, filename As String, timeout As Integer) As Boolean
ahttp = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
ahttp.SetPort(port)
ahttp.SetUrl(url)
ahttp.AddHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3")
ahttp.EnableEncodings(True)
result = ahttp.AsyncGetToFile(filename)
If result
While True
msg = Wait(timeout, port)
If Type(msg) = "roUrlEvent"
Print "AsyncGetToString: msg.GetResponseCode() = " + msg.GetResponseCode().ToStr () + ". msg.GetFailureReason () = " + msg.GetFailureReason ()
If msg.GetResponseCode() <> 200
result = False
Endif
Exit While
Else If Type (msg) = "Invalid"
Print "AsyncGetToString: timeout"
ahttp.AsyncCancel()
result = False
Exit While
Else
Print "AsyncGetToString: Unknown event: " + Type (msg)
Endif
End While
Endif
Return result
End Function
Also, when posting code in the forums, it's a lot easier to read if you enclose your code in "Code" tags. (Just click the "Code" button above the text entry box then insert your code between the code and /code tags).