How to output a QNetworkRequest to a raw Http request?

812 Views Asked by At

For Debugging purposes, I would like to examine the QNetworkRequests that I build and see if they are formatted correctly.

However, I do not see how to output them to a string format based upon their api.

How can I go about viewing the raw http request?

1

There are 1 best solutions below

0
Waqar On

You can use something like this to debug your requests generally:

#include <QDebug>

void debugRequest(QNetworkRequest request, QByteArray data = QByteArray())
{
  qDebug() << request.url().toString(); //output the url
  const QList<QByteArray>& rawHeaderList(request.rawHeaderList());
  foreach (QByteArray rawHeader, rawHeaderList) { //traverse and output the header
    qDebug() << request.rawHeader(rawHeader);
  }
}