How can I read POST data in a Wt application?
Added by Amir Hadzic about 2 years ago
Hello Everyone!
I have a project where I'm going to send POST data to my Wt application which is going to parse and insert that data into the database. How can I read that data in my application? The POST data is going to be sent from another application (for example, a python script).
Thank you!
Replies
RE: How can I read POST data in a Wt application? - Added by Wim Dumon about 2 years ago
This is supported through a WResource, but the support could be improved.
WResource::handleRequest() has a Http::request parameter, and the method in() returns the contents of your POST request. Normally, WResources live within a session, and the URL is auto-generated. If you need the URL to be fixed and usable without a session, install your resource as a static resource (WServer::addResource()).
By coincidence, this question also popped up on our mailing list today. See also Koen's answer there...
RE: How can I read POST data in a Wt application? - Added by Amir Hadzic about 2 years ago
Ok, thank you very much.
RE: How can I read POST data in a Wt application? - Added by Amir Hadzic about 2 years ago
Ummm, I don't know where to start. Can you give me a hint on how could I write a simple application that just prints out all POST data it receives? Thank you...
RE: How can I read POST data in a Wt application? - Added by Amir Hadzic about 2 years ago
Nevermind, I managed to read POST & GET data with WEnvironment which is passed as an argument (env) to WApplication constructor. Is this the right way?
RE: How can I read POST data in a Wt application? - Added by Koen Deforche about 2 years ago
Hey Amir,
This is the way if you want to do this for a request posted to a new session.
If you have an existing session, you will need to use similar API found in the Http::Request object from within WResource::handleRequest().
Regards,
koen
RE: How can I read POST data in a Wt application? - Added by Amir Hadzic about 2 years ago
I just started using Wt, so I'm not pretty sure how to use WResource. Do I create an WAnchor in my application and pass my custom WResource to WAnchor's constructor?
RE: How can I read POST data in a Wt application? - Added by Koen Deforche about 2 years ago
Hey Amir,
That's exactly what you need to do. You can also use WFileResource to serve from a file if you do not want/need to generate the contents on the fly.
Regards,
koen