QNetworkReply: How to get request (NOT response) header information

  • Hi,
    so far I was able to get the response Headers from a request send from a QNetworkAccessManager but Iam also interested in the request header which is send to the server but I am not able to get it.

    To get the response header I connected to the finished slot and when look into the QNetworkReply object.

    void harbinger::replyFinished(QNetworkReply * response)
    //set status code
    ui.statusCodeEdit->setText(response->attribute(QNetworkRequest::Attribute::HttpStatusCodeAttribute).toString() + " - " + (response->attribute(QNetworkRequest::Attribute::HttpReasonPhraseAttribute).toString()));
    QList<QByteArray> headerlist = response->rawHeaderList();
    QByteArray header;
    for (auto it = headerlist.cbegin(); it != headerlist.cend(); ++it)
    	header = response->rawHeader(*it);
    	QString test = "<b>" + *it + ": " + "</b>" + header;

    I tried following things to get the request header:

    1. I tried to look into the object that is returned bei QNetworkAccessManager::get() which has completely no header information
    2. I connected to the readyRead() signal which only gives me the header infos from the response
    3. I connected to the metaDataChanged() signal but I also get the response header
    4. I also looked into the constructed QNetworkRequest object before it was passed to the QNetworkAccessManager::get function but this was also empty.
    5. I tried also to look into the QNetworkRequest object that is in the QNetworkReply when the finished slot is invoked but where was also no request header information.

    How can I get the header information which QNetworkAccessManager send to the server?
    If I look into wireshark I see that per default the QNetworkAccessManager sends header information even if none are set by myself but Iam not able to get the information.

    On which point do I have to put my "Net" to get the info?

    Edit: Ok, I tested what happens if I manually add header to the request and looked into the request object in QNetworkAccesManager::get scope and in finished() scope and I was able to retrieve header information but only the ones that I put in but if I look to wireshark I see more header information.

    GET /myurl/!/about HTTP/1.1 <-- protocol info
    Conenction: Keep-Alive
    Accept-Encoding: gzip, deflate
    Accept-Language- de-de, en.*
    User-Agent: Mozilla/5.0 <-- ? is it internally a mozilla engine?
    Host: blablubb:1080

    I see this information in wireshark so it must be coming from the QNetworkAccessManager?


Log in to reply

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