Catching HttpSocket redirect final URL

  1. 3 months ago
    Edited 3 months ago by Tony C

    I am using code based on the Xojo downloader example, fixed to auto use the file url etc.

    When my HTMLviewer detects a file download it downloads the file using httpsocket and it works great, all but when the file is a redirected download. Example..

    www.site1.com/file.zip

    redirects to

    www.site2.com/folder/file.zip

    This is being done via a 302 redirect and I am detecting this in the HeadersReceived event on the httpsocket

    What I want to do is catch the final "true" url of the file and have the socket download it from the redirected url

    In HTTP 30X responses, the redirect URL is included as the Location header in the HeadersReceived event:

    Sub HeadersReceived(headers as internetHeaders, httpStatus as integer)
      Dim url As String = headers.CommaSeparatedValues("Location")
      Me.Get(url)
    End Sub
  2. Andrew L

    May 19 Answer San Francisco, CA, USA

    In HTTP 30X responses, the redirect URL is included as the Location header in the HeadersReceived event:

    Sub HeadersReceived(headers as internetHeaders, httpStatus as integer)
      Dim url As String = headers.CommaSeparatedValues("Location")
      Me.Get(url)
    End Sub
  3. Thanks Andrew!

    @Andrew L In HTTP 30X responses, the redirect URL is included as the Location header in the HeadersReceived event:

    Sub HeadersReceived(headers as internetHeaders, httpStatus as integer) Dim url As String = headers.CommaSeparatedValues("Location") Me.Get(url) End Sub

or Sign Up to reply!