HttpRequest redirects

Discussion in 'Bugs & wishlist' started by wimpie3, Mar 7, 2011.

  1. wimpie3

    wimpie3 Well-Known Member Licensed User

    Can you please make HttpRequest (optionally) listen to http-redirects?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It should follow redirects automatically.
     
  3. wimpie3

    wimpie3 Well-Known Member Licensed User

    It does, indeed :)

    But after a redirect, it's impossible to know the current url...
     
  4. wimpie3

    wimpie3 Well-Known Member Licensed User

    Can you please either add an option to make httpclient NOT follow redirects, or to get the current url that httpclient was redirected to? I'm stuck in my latest basic4android application because of this. Thanks!!
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    See the updated library: http://www.basic4ppc.com/forum/addi...ates/8183-http-library-v1-08-a.html#post46003

    You can now manually handle redirects:
    (Basic4android . com redirects to Basic4ppc . com)
    Code:
    'Activity module
    Sub Process_Globals
        
    Dim hc As HttpClient    
    End Sub

    Sub Globals
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    If FirstTime Then
            hc.Initialize(
    "hc")
            hc.SetHttpParameter(
    "http.protocol.handle-redirects"False)
        
    End If
        
    Dim req As HttpRequest
        req.InitializeGet(
    "http://www.basic4android.com")
        hc.Execute(req, 
    1)
    End Sub
    Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
        
    Log("success: " & Response.GetString("UTF8"))
    End Sub
    Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
        
    Log("Error")
        
    Log(StatusCode)
        
    If Floor(StatusCode / 100) = 3 Then '3xx status
            If response <> Null Then
                
    Log("Redirect to: " & response.GetHeaders.Get("Location"))
            
    End If    
        
    End If
    End Sub
     
  6. wimpie3

    wimpie3 Well-Known Member Licensed User

    And if a redirection took place, is there a way to see the new, current url?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    When redirections are handled automatically you cannot get the target URL.
    If you handle the redirections yourself then the target URL is displayed with this line from the above code:
    Code:
    Log("Redirect to: " & response.GetHeaders.Get("Location"))
     
  8. mhartwig

    mhartwig Member Licensed User

    I tried this, but cannot seem to get this to work. I am using httputils2. Has anything changed?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    What exactly are you trying to implement?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice