B4J Question [SOLVED] Server Handler - How will give at client the requested.. response

Magma

Expert
Licensed User
Longtime User
Hi there...

about B4J Server...

i have some... "silly" question

i want the client work from browser and send query to get response... like this:
B4X:
www.myserver.ext:54021/myhandler?geta=100

Actually when geta = 100 the server will response a msg.... easy but somewhere lost the ball..

B4X:
'Class module
Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim In As InputStream = req.InputStream
    Dim reqType As String = req.GetParameter("geta")

        resp.ContentType = "text/html"
       
    Dim tr As TextReader
     tr.Initialize(In)
    
   if reqtype="geta" and tr.readall="100" then

resp.write("SOMETHING!")

    End If


End Sub

I am totally wrong....
 

OliverA

Expert
Licensed User
Longtime User
the GetParameter method returns the content of the parameter in question. So, reqType would now contain either an empty string if the parameter was not found or the value of the parameter. So your If statement would be (added error message):
B4X:
if reqtype="100" then
   resp.write("SOMETHING!")
Else
   resp.SendError(400, "Missing parameter: geta")
End If
 
Upvote 0
Top