I don't need some headers in QNetworkRequest



  • For example, I don't need the header "User-Agent:Firefox...".
    So I program like this:
    QNetworkRequest req;
    req.setRawHeader("User-Agent", "");
    But it is useless;
    Or I don't set the header, but the User-Agent will still be in the header of http.
    Thank you for your help!


  • Moderators

    @suclida

    When it is useless, why are you setting it?



  • @koahnig Or I don't set the header, but the User-Agent will still be in the header of http.


  • Moderators

    @suclida

    Setting the raw header make only sense IMHO when you have to do something off the main track.
    Check out the detailed infomration for QNetowrkAccessManager

    The second sets the "User-Agent" , but you do not have to do it. This is merely a example of a more enhanced usage.


  • Moderators

    req.setRawHeader("Foo", "");
    

    This does not remove a header. It sets header value to be an empty string. To remove a header pass an empty array:

    req.setRawHeader("Foo", QByteArray());
    

    You can also set or clear known headers like User-Agent via setHeader():

    req.setHeader(QNetworkRequest::UserAgentHeader, QVariant());
    

Log in to reply