Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
PHP post via QWebEngine ?
I'm new to Web stuff and PHP, and here is my question :
I'm loading a php page in a QWebEnginePage. This page has a login form, and I would like to automate the login and access to the next page.
I don't even know where to begin to send the credential to the page, and how to submit them to reach the next page.
It seems a POST is possible with QNetworkAccessManager::post(), but how to interact with the webpage ?
Any help would be appreciated, at least to have a starting point for further researchs.
plaristote last edited by
I had to do something similar lately... and I wasn't succesful, at least not with QWebEngine. It seems that security concern prevents some types of interactions with a page's content.
What you're trying to do might not be possible at all. At this point, I'd say you have two options left:
If you are the owner of the web application, then I suggest you use WebSockets to have the web application and the Qt application communicate. Basically, you want to setup a WebSocket server from your Qt application, and have the web application try to connect to that local WebSocket and send whatever relevant information you need to your Qt application.
It's not that easy to setup, and there are some important details I'm probably forgetting, because ultimately, I personally ditched QWebEngine, and had my clients open an external web browser to login. The local WebSocket technique did work between my Qt application and the external web browser.
If you are not the owner of the web application, it's going to be trickier. I would suggest you ditch QWebEngine altogether: send the POST request directly from Qt, and then extract the relevant data you need from the answer: the cookies that would allow you to make further requests, or the page content using an HTML parser. Qt doesn't provide anything for the latter, AFAIK, but libxml2 could parse HTML for you.
there is more involved than simply sending a request. The response most probably will set cookies. Which will need to be set for all continuous occuring requests.
Thank you for your help !
I'm not the owner of the web app, so yeah, I understand I'm in the worst case scenario.
Interesting, I'm gonna check this. Thanks a lot !