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



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



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



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



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



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



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



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

    1. 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
    2. 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.


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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.