Bug: http calls don't work with a proxy

wimpie3

Well-Known Member
Licensed User
Longtime User
Currently, http calls from BASIC4ANDROID seem to be failing with status code -1 when a proxy server is defined in the Access Point settings.

Surfing with the browser on the emulator works fine.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Erel,

This works fine for the first http call. However, when I call HttpClient1.Execute(...) for a second time, the -1 error returns.

Wim
 

wimpie3

Well-Known Member
Licensed User
Longtime User
I've used the Flickr viewer as an example. Changed

If FirstTime Then
HttpClient1.Initialize("http")
End If

to

If FirstTime Then
HttpClient1.Initialize("http")
HttpClient1.SetProxy("120.2.165.159","5865","http")
End If

This works fine when you click on the connect button once, but fails on a second click with the following message:

Reason: java.net.sockettimeoutexception, StatusCode: -1
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Your wish is my command. After doing this:

HttpClient1.SetProxy("myproxyaddress","myproxyport","http")
HttpClient1.Execute(request, MainRequestId)

it still doesn't work... sockettimeoutexception when HttpClient1.Execute is executed a second time.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do you have access to the proxy logs? Maybe the proxy is blocking the call for some reason.

I suggest that you try a simpler application like the following one:
B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim hc As HttpClient
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        hc.Initialize("hc")
        hc.SetProxy("yourhost", 1111, "http")
    End If
End Sub
Sub Activity_Click
    Dim req As HttpRequest
    req.InitializeGet("http://www.google.com")
    hc.Execute(req, 1)
End Sub
Sub hc_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
    Log("Error: " & Reason & " " & StatusCode)
    ToastMessageShow("Error", True)
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Log("Success")
    Log(Response.GetString("UTF8"))
    Response.Release
    ToastMessageShow("Success", True)
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
It connects to Google every time you press on the activity.
Uncheck the "Filter" option in the logs and see if there is any relevant message (assuming it fails to connect).
 

wimpie3

Well-Known Member
Licensed User
Longtime User
The code above executes fine the first time. I see the html code from the google home page in the log window.

However, on a second click, the log shows:

Error: java.net.SocketTimeoutException -1

I'm pretty sure my proxy works fine, I can surf with the proxy activated on the emulator without any problem.

In case you want to try it out yourself, I'm using NTLM authorization Proxy Server v0.9.9.5 from Dmitry Rozmanov.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
No problems on a real device, but of course, I'm not using a proxy in that case.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…