Access QNetworkRequest data before submitting

Is there a way to see the data that will be sent (or sent) during (or after) a call to QNetworkAccessManager::post(QNetworkRequest,QByteArray) on the client side?

In other words, I would like to see a raw HTTP request in it:

 POST /somepage.php HTTP/1.1 Host: example.com Content-Type: application/x-www-form-urlencoded Content-Length: 19 name=need&just=tosee 
+4
source share
1 answer

It has been some time since I had to debug my queries and everything could be changed in Qt, but I needed to access different parts of the queries using various functions to get all the details.

I created a wrapper for the post function, which will print the details before sending the request. Here's a snippet of code that retrieves and prints URLs, source headers, and data, for example:

 void debugRequest(QNetworkRequest request, QByteArray data = QByteArray()) { ... qDebug() << request.url().toString(); const QList<QByteArray>& rawHeaderList(request.rawHeaderList()); foreach (QByteArray rawHeader, rawHeaderList) { qDebug() << request.rawHeader(rawHeader); } qDebug() << data; ... } 
+1
source

Source: https://habr.com/ru/post/1479216/


All Articles