Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PHP post via QWebEngine ?

PHP post via QWebEngine ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 461 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duarna
    wrote on 19 Feb 2021, 10:40 last edited by
    #1

    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

    R 1 Reply Last reply 19 Feb 2021, 13:50
    0
    • P Offline
      P Offline
      plaristote
      wrote on 19 Feb 2021, 13:41 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D duarna
        19 Feb 2021, 10:40

        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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 19 Feb 2021, 13:50 last edited by raven-worx
        #3

        @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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • D Offline
          D Offline
          duarna
          wrote on 22 Feb 2021, 08:34 last edited by
          #4

          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 ?

          R 1 Reply Last reply 22 Feb 2021, 08:52
          0
          • D duarna
            22 Feb 2021, 08:34

            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 ?

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 22 Feb 2021, 08:52 last edited by
            #5

            @duarna
            https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-contentmanipulation-example.html

            You can inject JavaScript which does what i said (fill and submit the login form).

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • D Offline
              D Offline
              duarna
              wrote on 22 Feb 2021, 14:33 last edited by
              #6

              Interesting, I'm gonna check this. Thanks a lot !

              1 Reply Last reply
              0

              1/6

              19 Feb 2021, 10:40

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved