B4J Question B4J server, receive parameter from url

Mostez

Well-Known Member
Licensed User
Longtime User
I use attached html page to confirm if night drive trip is required (at client side) the page url is sent to client by email for confirmation, like:
ordernum=12345
I want to receive the ordernum parameter (12345 from link) at server side and put in Order Number text box to handle it as required

How to do that?

TIA
 

Attachments

  • conf.jpg
    conf.jpg
    13.7 KB · Views: 95

DonManfred

Expert
Licensed User
Longtime User
Check the content of the request-Object.


Snap20.png



B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    req.GetSession.RemoveAttribute("myNumber")
    Dim attribs As Map = req.ParameterMap
    
    For Each key As String In attribs.Keys
        Log($"Key ${key} = ${attribs.Get(key)}"$)
    Next
    'Log(req.GetSession)
End Sub
 
Last edited:
Upvote 0

cklester

Well-Known Member
Licensed User
Your URL and event handler do not correspond, it seems. (A call to an HTTP URL does not trigger a websocket event handler.)

I start the session like this : http://127.0.0.1:17178/nightdrive/?ordernum=12345

this code returns null
B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
    Log(ws.Session.GetAttribute("ordernum"))   
End Sub

You either need to make a websocket call (ws://127.0.0.1:17178/nightdrive/?ordernum=12345) or use a server handler (as @DonManfred said).
 
Upvote 0
Top