Android Question I am trying to use the GET in my HTML page to return the contents of the textbox in the URL

Jack Howard

Member
Licensed User
Longtime User
I am trying to use the GET in my HTML page to return the contents of the textbox in the URL

My browser shows the correct URL after I press submit button
http://192.168.0.101:5555/ok?fname=123&lname=abc
where 123 & abc are the contents are the contents of the two text boxes

But the server never gets back the URL.

It truncates on the ?

Here is the code

B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)





  Log("Client: " & Request.RemoteAddress)
  Log("Get RequestURI=" & Request.RequestURI) 'handle the request based on the URL
  Log("Get Method=" & Request.Method) 'handle the request based on the URL
  Log("Get GET=" & Request.GetParameter("GET")) 'handle the request based on the URL
  Log("Get POST=" & Request.GetParameter("POST")) 'handle the request based on the URL
  Log("Get MSG=" & Request.GetParameter("message"))










  Select True




  
  Case Request.RequestURI = "/set"
   Response.SendString("<!DOCTYPE html><html><body><form action='/ok' method='get' target='_blank'>First name: <input Type='text' name='fname'><br>Last name: <input Type='text' name='lname'><br><input Type='submit' value='Submit'><br></form></body></html>")





  Case Request.RequestURI = "/ok"




   Response.SendString("<!DOCTYPE html><html><body><p>" & "All OK" & "</p></body></html>")





  Case Else
    Log("Something went wrong")




  End Select




End Sub

My logs show I am not catching anything in Get either, I have also tried Post and the results are the same

These are the logs

Client: 192.168.0.102
Get RequestURI=/ok
Get Method=GET
Get GET=
Get POST=
Get MSG=
 

OliverA

Expert
Licensed User
Longtime User
Log("Get GET=" & Request.GetParameter("GET")) 'handle the request based on the URL
Log("Get POST=" & Request.GetParameter("POST")) 'handle the request based on the URL
Log("Get MSG=" & Request.GetParameter("message"))
These don't work they way you are thinking (PHP?). In a plain GET or POST request, you can access the parameters with the GetParameter method. The word Get in that method has nothing to do with the method (GET/POST/etc) that was used to access your page. The reason your third GetParameter request shows nothing is that you do not have a parameter named "message". You just have "fname" and "lname", so Request.GetParameter("fname") should result in "123" and Request.GetParameter("lname") should result in "abc". Also
Log("Get RequestURI=" & Request.RequestURI) 'handle the request based on the URL
the RequestURI only returns the part of the URL that is not related to the host and is not a parameter (only the fragment between the after the host : port information and before the ?). You may be looking for FullRequestUri. That method returns, host, port, path, and parameter information.
 
Upvote 0

Jack Howard

Member
Licensed User
Longtime User
You are correct
B4X:
    Log("Get fname=" & Request.GetParameter("fname")) 'Get Textbox contents
    Log("Get lname=" & Request.GetParameter("lname")) 'Get Textbox contents

Gives me the contents.

I really appreciate how quickly you solved this for me

Thanks
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
These don't work they way you are thinking (PHP?)

This is why I love ABM. We ABM users don't have to consider or deal with such...
No PHP, no HTML, no CSS and no JS - unless of course - you want or need to. I (rarely) need to - or ever want to.

When it is required, the result and learning curve has been "relatively" painless. I know enough to be extremely dangerous.

Case Request.RequestURI = "/set"
Response.SendString("<!DOCTYPE html><html><body><form action='/ok' method='get' target='_blank'>First name: <input Type='text' name='fname'><br>Last name: <input Type='text' name='lname'><br><input Type='submit' value='Submit'><br></form></body></html>")

Question: For me - what the hell does that mean?
Answer: I don't care! Some other smart fellow cut me out of the "need to know" (and create that) loop...

When ever I see this - I rant. From (near) death to born again with a inspirational outlook on web dev...
 
Upvote 0
Top