PHP post via QWebEngine ?
-
wrote on 19 Feb 2021, 10:40 last edited by
Hi !
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.
Thank you,
Arnaud -
wrote on 19 Feb 2021, 13:41 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.
-
-
Hi !
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.
Thank you,
Arnaud@duarna
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.You should probably better inject some JavaScript which fills and submits the form in the page. You can show the webview until the landing page is loaded.
-
wrote on 22 Feb 2021, 08:34 last edited by
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.
@raven-worx What do you mean by injecting some JavaScript ? How does this work ?
-
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.
@raven-worx What do you mean by injecting some JavaScript ? How does this work ?
@duarna
https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-contentmanipulation-example.htmlYou can inject JavaScript which does what i said (fill and submit the login form).
-
wrote on 22 Feb 2021, 14:33 last edited by
Interesting, I'm gonna check this. Thanks a lot !
1/6