Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I don't need some headers in QNetworkRequest

I don't need some headers in QNetworkRequest

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    suclida
    wrote on last edited by suclida
    #1

    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!

    K 1 Reply Last reply
    0
    • S suclida

      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!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @suclida

      When it is useless, why are you setting it?

      Vote the answer(s) that helped you to solve your issue(s)

      S 1 Reply Last reply
      0
      • K koahnig

        @suclida

        When it is useless, why are you setting it?

        S Offline
        S Offline
        suclida
        wrote on last edited by
        #3

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

        K 1 Reply Last reply
        0
        • S suclida

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

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @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.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5
            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());
            
            I 1 Reply Last reply
            1
            • Chris KawaC Chris Kawa
              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());
              
              I Offline
              I Offline
              Ivan B
              wrote on last edited by
              #6

              @Chris-Kawa This is not working for the headers I set:

              request.setRawHeader("Accept-Encoding", QByteArray());
              request.setRawHeader("Accept-Language", QByteArray());
              

              I still see in Wireshark that the headers are not gone

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Ivan-B Seems like a long standing bug: QTBUG-9463. There even was a patch to fix this going through but it got abandoned for some reason. You might ask the devs on the mailing list what happened.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved