Android Tutorial Embed an Http Server in your Android Application

Status
Not open for further replies.

ajk

Active Member
Licensed User
Longtime User
When I try to download page from http server on android with:
<p>ąśżźćńłó</p>
I get the:
<p>�������</p>
on WIN10 and android devices

how to handle this?
 

ajk

Active Member
Licensed User
Longtime User
Yes. Slightly modified by adding phrase mentioned above.
When I open the example file (in FILES folder) with browser it display correctly. The problem appear when I open the file served by http server from android phone.

OK SOLVED by adding:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
it was the utf-8 related issue
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
I tried using the http server by sending with POST a name value pair from vb.net with the following code:

(the sValue varible length is about 3850 characters)

B4X:
                    If sInfServ = "" Then
                sTempInfServ = InputBox("""Device address"" reported by http server:", "Insert IP", "")
                sTempInfServ = sTempInfServ.Replace(",", ".")
            Else
                sTempInfServ = sInfServ
            End If

            Dim nv As New NameValueCollection
            Dim sValue As String = Uri.EscapeDataString(sJson)

            nv.Add("json", sValue)

            Using webcl As New WebClient
                Try
                    Dim b() As Byte
                    b = webcl.UploadValues("http://" & sTempInfServ & ":5556/nvget/", nv)
                    MsgBox(System.Text.Encoding.UTF8.GetString(b))

                    sInfServ = sTempInfServ
                Catch ex As Exception
                    MsgBox("Internal error: " & ex.Message)
                    sInfServ = ""
                End Try
            End Using


The code in the 'http server' project is:

B4X:
Sub HandleNVGET (Request As ServletRequest, Response As ServletResponse)
    
    Try
    
        Dim sJson As String = DecodePath(Request.GetParameter("json"))
    
        Dim jp As JSONParser
        jp.Initialize(sJson)
        Dim l As List
        l.Initialize
        l = jp.NextArray
        .
        .
        .
        .
        .

    Catch
       Log(LastException)
       Response.SendString("Received the data but an error occured.")
    End Try

End Sub


When I compile the b4a project in debug mode everything works perfect. When I turn the compile mode in 'Release (obfuscated)' I get the error in the VB.NET app:
"The request was aborted: The request was canceled."

The error seen on the b4a side in logs is :"(NetworkOnMainThreadException) android.os.NetworkOnMainThreadException"

Any Ideas and suggestions on this?

Thanks
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Is there any chance of this library being updated to more closely resemble B4J's jServer library? What would be really useful is if this library could run a WebSockets server like jServer. They're both based on jetty.
 

BluSky76

Member
Licensed User
Longtime User
I don't know how they externally send requests to my Android Server. Currently to solve the problem, temporarily, with Chrome you need to install an ALLOW-CORS plugin.
 

Ganiadi

Active Member
Licensed User
Longtime User
Hi Erel,

i Tried to install the server into mini pc device with android 9 Pie, it works, but when i click START SErver it raised error






Pls advice,
Tks
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…