Unsolved 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! -
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.
-
Setting the raw header make only sense IMHO when you have to do something off the main track.
Check out the detailed infomration for QNetowrkAccessManagerThe second sets the "User-Agent" , but you do not have to do it. This is merely a example of a more enhanced usage.
-
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
viasetHeader()
:req.setHeader(QNetworkRequest::UserAgentHeader, QVariant());
-
@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
-
@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.