HttpRequest redirects

wimpie3

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

wimpie3

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

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

wimpie3

Well-Known Member
Licensed User
Longtime 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

B4X founder
Staff member
Licensed User
Longtime User
See the updated library: http://www.b4x.com/forum/additional...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
Longtime User
And if a redirection took place, is there a way to see the new, current url?
 

mhartwig

Member
Licensed User
Longtime User
I tried this, but cannot seem to get this to work. I am using httputils2. Has anything changed?
 
Top