Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. difference between QWebView::load() and QNetworkAccessManager::post
Forum Updated to NodeBB v4.3 + New Features

difference between QWebView::load() and QNetworkAccessManager::post

Scheduled Pinned Locked Moved Unsolved Qt WebKit
8 Posts 3 Posters 3.2k Views 2 Watching
  • 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.
  • 6 Offline
    6 Offline
    6ygyjiau
    wrote on last edited by
    #1

    I have my custom QNetworkAccessManager and QWebView . I take a request created by QWebView change it and post it. If i post it with QWebView::load() everything works but page reloads. I want to post it with post method of my custom QNetworkAccessManager but server not accept it .

    K 1 Reply Last reply
    0
    • 6 6ygyjiau

      I have my custom QNetworkAccessManager and QWebView . I take a request created by QWebView change it and post it. If i post it with QWebView::load() everything works but page reloads. I want to post it with post method of my custom QNetworkAccessManager but server not accept it .

      K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #2

      @6ygyjiau Do you want to open page with HTTP POST request? Or just get results from this request?

      6 1 Reply Last reply
      0
      • Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @6ygyjiau As I understand, QWebView::load(const QUrl & url) will do an HTTP GET request to such url and then will display the response. On the other hand, QNetworkAccessManager::post(...) will do an HTTP POST request, and will give you a QNetworkReply with the response of such request. You then need an extra step to process/interpret the reply accordingly.
        What I'm seeing now is that you have an overloaded QWebView::load(const QNetworkRequest & request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray()) so you can have QWebView do an HTTP POST request and later on it will display the response of such request.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        6 1 Reply Last reply
        0
        • K Konstantin Tokarev

          @6ygyjiau Do you want to open page with HTTP POST request? Or just get results from this request?

          6 Offline
          6 Offline
          6ygyjiau
          wrote on last edited by
          #4

          @Konstantin-Tokarev I just need to make post request and I don't need any reply.

          K 1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @6ygyjiau As I understand, QWebView::load(const QUrl & url) will do an HTTP GET request to such url and then will display the response. On the other hand, QNetworkAccessManager::post(...) will do an HTTP POST request, and will give you a QNetworkReply with the response of such request. You then need an extra step to process/interpret the reply accordingly.
            What I'm seeing now is that you have an overloaded QWebView::load(const QNetworkRequest & request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray()) so you can have QWebView do an HTTP POST request and later on it will display the response of such request.

            6 Offline
            6 Offline
            6ygyjiau
            wrote on last edited by 6ygyjiau
            #5

            @Pablo-J.-Rogina you are right , I am using overload QWebView::load(const QNetworkRequest & request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray()) with QNetworkAccessManager::PostOperation and server accept it . But the same request with QNetworkAccessManager::post server not accept. I can't see the request with QNetworkAccessManager::post in QWebInspector , so I can't tell why it happents.

            1 Reply Last reply
            0
            • 6 6ygyjiau

              @Konstantin-Tokarev I just need to make post request and I don't need any reply.

              K Offline
              K Offline
              Konstantin Tokarev
              wrote on last edited by
              #6

              @6ygyjiau said in difference between QWebView::load() and QNetworkAccessManager::post:

              I just need to make post request and I don't need any reply

              In this case you can just use QNetworkAccessManager::post. If server wants to see cookies from QWebView, use QNetworkAccessManager from QWebPage to do POST. If server expects certain Refer or User-Agent headers, add them to your request.

              But yes, QWebView::load(request, QNetworkAccessManager::PostOperation, data) should work too. But it's a bit excessive if you don't need results of request.

              1 Reply Last reply
              0
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @6ygyjiau several things here: 1) why to use QNetworkAccessManager::post if you aren't interested in the reply? and even more, knowing that QWebView::load() works well
                2) If you cannot see the actual request with QWebInspector, please go down the wire and use wireshark to capture the network traffic and compare both requests (with load() and with post()). For sure you'll be able to tell the difference
                3) As suggested by @Konstantin-Tokarev if you definitively need to use QNetworkAccessManager::post() you may want to use the QNAM of the QWebView. In that way you'll be using the same exact headers as the QWebView::load() call.

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                6 1 Reply Last reply
                0
                • Pablo J. RoginaP Pablo J. Rogina

                  @6ygyjiau several things here: 1) why to use QNetworkAccessManager::post if you aren't interested in the reply? and even more, knowing that QWebView::load() works well
                  2) If you cannot see the actual request with QWebInspector, please go down the wire and use wireshark to capture the network traffic and compare both requests (with load() and with post()). For sure you'll be able to tell the difference
                  3) As suggested by @Konstantin-Tokarev if you definitively need to use QNetworkAccessManager::post() you may want to use the QNAM of the QWebView. In that way you'll be using the same exact headers as the QWebView::load() call.

                  6 Offline
                  6 Offline
                  6ygyjiau
                  wrote on last edited by
                  #8

                  @Pablo-J.-Rogina I already use QNAM from QWebView. I just sem my custom QNAm in QWebView

                  1 Reply Last reply
                  0

                  • Login

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