HTTP-Library on different Port?

Icinger

Member
Licensed User
Longtime User
Hi!

Happy New Year, everybody!

First Post here and already a Question

I need to send a HTTP-Request un a different Port than 80.....

Normaly, it should work with "http://test.com:5544".....
But somehow, I can't get a connection to this Server. If i paste the adress from my Code to a Browser-Window, it works....

Seems, Linux/Android/B4a dosen't handle the Port correctly.....

Any Idea anybody, how to handle this?

Cheers,

Icinger
 

Icinger

Member
Licensed User
Longtime User
It should work (I just verified it). Are you using the emulator or a real device? Do you get any error message?

Tried it on 2 real Devices (Galaxy i9000 and Galaxy Tab 10.1).

Get no Error or anything else, only the Timeout-Event fires......

BTW, thats my Code:

B4X:
Sub Process_Globals
    Dim URL As String
    URL = "http://myadress.dyndns.org/GetAll"
    Dim HttpClient1 As HttpClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
   HttpClient1.Initialize("HttpClient1")
   httpclient1.SetProxy("guttmann.homeip.net",4455,"http")
   getdatafromserver
End Sub

Sub GetDataFromServer
        Dim request As HttpRequest
   request.InitializeGet(URL)
        request.Timeout = 100000 'set timeout to 10 seconds
        If HttpClient1.ExecuteCredentials(request, 1,"user","pass") = False Then Return 
End Sub

Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    result = Response.GetString("UTF8") 'Convert the response to a string
End Sub

Sub HttpClient1_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
    Log(Reason)
    Log(StatusCode)
    msg = "Error connecting to server."
    If reason <> Null Then msg = msg & CRLF & Reason
    ToastMessageShow (msg, True)
End Sub

also tried it this way:
B4X:
Sub Process_Globals
    Dim URL As String
    URL = "http://myadress.dyndns.org:5544/GetAll"
    Dim HttpClient1 As HttpClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
   HttpClient1.Initialize("HttpClient1")
   getdatafromserver
End Sub
 
Last edited:
Upvote 0

Icinger

Member
Licensed User
Longtime User
Seems, i'm getting closer.....
Now I get as Error:

org.apache.http.conn.HttpHostConnectException: Connection to http://server.dyndns.ord:5544 refused

What's interessting, since there is no Apache running on the Target! :confused:

Thats more than strange:
If I replace "server.dyndns.org" with the IP-Adress, the it works......If i reverse to "server.dyndns.org", is stops working............
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If I replace "server.dyndns.org" with the IP-Adress, the it works......If i reverse to "server.dyndns.org", is stops working

Question, if you enter the IP on the browser, does it change to "server.dyndns.org"?, if that's the case it means the DNS is being refreshed so I don't think your app will work, I could be wrong though.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Sorry for hi-jacking this thread...

I also had a problem connecting to a server since I did not include the user-agent. In B4PPC it is possible to set user-agent using request.useragent="xxx". I can't find this in Android although I saw some code by Andrew using reflection which seems to set user-agent.

Erel: Could you add user-agent to the HTTP-library?

Another question: Using Android accessing a webserver by code, what should we put as user-agent (if required)?


The problem is elsewhere. Maybe the server rejects your request because you don't have a user agent.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
What's interessting, since there is no Apache running on the Target!
Android Http implementation is based on Apache HttpComponents projects. It is not related to an Apache server.

Erel: Could you add user-agent to the HTTP-library?
Already supported:
B4X:
req.SetHeader("User-Agent", "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1")
 
Upvote 0
Top