Post data using Xojo Web

I am using Xojo Web 2017R1 to create a simple web app that sends search parameters from a browser to a web server, which will query a database and return a response to the browser. I want to send the query using a POST, rather than a GET.

I was under the impression that Xojo Web was designed for this, but I have not found a way to send data from a browser via a POST… the ShowURL command uses the GET mechanism, but I do not want the data to be a visible part of the URL. Furthermore, I would like to send the search parameters to the server via a JSON string.

Most importantly, the server needs to support multiple users - probably 10 to 100.

Is Xojo Web the right tool for this task? If so, can you give me some pointers for making it work? I’ve studied the Eddie’s Electronics app quite a bit, but if the answer is there, then it’s not obvious. It would be great if there was some sort of skeleton that would get people started with Xojo Web… perhaps even a best-practices document.

Thanks in advance for your help!
Don

First of all, xojo web is primarily designed to be front AND back end if a web app. If you want to be able to send raw http requests and respond to them, take a peek at the docs for HandleUrl and HandleSpecialUrl. There you can get access to the post data.

Yes, it was my understanding that Xojo Web was designed to be front AND back end of a web app - that is the reason I purchased it. But how do I transfer the query data from the browser to the server in Xojo Web (i.e. the equivalent of a POST)? If I create a WebButton on a browser, what code should I put in its action event to send the query data to the server, so it is not visible in the URL (i.e. like a POST, rather than a GET)?

I’m sure it must be very simple, and I’ll probably kick myself for not figuring it out sooner, but I just need a hint to get me started. Is it something as simple as calling an App method from the action of the button?

Thanks for your help!
Don

Ya know, Greg, I just tested a call to an App-level method from a WebButton’s action event in the browser, and it seemed to work… just that simple. The app-level method simply wrote a string to the log database, and it proved that my query got there. The FireFox developer tools confirmed that it was via a POST, so I think that may be the key.

Now, my next question to you, is this: Is that the way it’s supposed to be done - i.e. a best practice - or is there another way that’s more inline with the design of Xojo Web? Something that will allow me to manage multiple sessions.

Thanks again,
Don

If your web app is making a POST request to a remote service, use an HTTPSocket. It can POST or GET, whichever you want. ShowURL is the wrong tool for the job.

If you want to send a POST request to your web app, use HandleURL.

[quote=328121:@Donald McCluskey]Ya know, Greg, I just tested a call to an App-level method from a WebButton’s action event in the browser, and it seemed to work… just that simple. The app-level method simply wrote a string to the log database, and it proved that my query got there. The FireFox developer tools confirmed that it was via a POST, so I think that may be the key.

Now, my next question to you, is this: Is that the way it’s supposed to be done - i.e. a best practice - or is there another way that’s more inline with the design of Xojo Web? Something that will allow me to manage multiple sessions.

Thanks again,
Don[/quote]
You’re missing the point. Xojo Web uses Ajax calls to send data to the server in the background and while it’s not a traditional full page POST method as you would do from a web browser form, it does use the POST protocol.

I think this will do what you want. Just don’t over-think it. Web was designed to work a lot like our desktop product in that you write code and it just works.

Just FYI. Blindly taking queries from the browser and executing them on the server is dangerous. Imagine someone sending DROP table or DELETE * FROM table. You could lose a lot of data, very quickly.

Hey Donald,

Let’s say you show a page with text fields and the user changes the data along with a save button. The user changes the values of some fields and then presses save. That code runs on the server and has access everything on the page. So there is no post…

Thanks, everyone, for helping me get oriented to Xojo Web. I was definitely over thinking it, but I think I can make it work from this point forward, with a little additional learning curve for handling multiple users.

I am planning on using prepared queries and not allowing users to issue whatever queries or commands that they desire.

Thanks again for your consideration and suggestions.
Don