Accessing QNetworkRequest data before it's sent
Asked Answered
L

1

10

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

In other words, I would like to see the raw HTTP request in it's entirety:

POST /somepage.php HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 19

name=need&just=tosee
Lovelady answered 5/5, 2013 at 7:46 Comment(0)
W
13

It was a while since I had to debug my requests and things may have been changed in Qt, but I had to access the different parts of the requests using various functions in order to obtain all the details.

I created a wrapper for the post function which would print the details before posting the request. Here's a code snippet that extracts and prints the URL, raw headers and data for instance:

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;
  ...
}
Wyckoff answered 6/5, 2013 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.