HttpRequest redirects

wimpie3

Well-Known Member
Licensed User
Can you please make HttpRequest (optionally) listen to http-redirects?
 

wimpie3

Well-Known Member
Licensed User
It does, indeed :)

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

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!!
 

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)
B4X:
'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
 

wimpie3

Well-Known Member
Licensed User
And if a redirection took place, is there a way to see the new, current url?
 
Top