How do I add a custom header to an already authorized QAbstractOAuth2 object?
-
Hello,
After being authorized, I'm using the object to make requests:
QAbstractOAuth2::get(), QAbstractOAuth2::put(), etc.How to add headers to the requests made by these functions?
Just like the function setUserAgent(), which works anytime, is there something for custom headers?
Thanks.
-
Hi,
Essentially a wild guess but I think prepareRequest might be what you are looking for.
-
@SGaist Thanks. =)
That basically worked this way:
QOAuth2AuthorizationCodeFlow *oaFlow; // ... *oaFlow gets authorized ... QNetworkRequest nrqRequest(QUrl("https://somesite.com/someres/somecmd?someparam")); // I don't know what the verb/body parameters are good for: oaFlow->prepareRequest(&nrqRequest,QByteArray(),QByteArray()); nrqRequest.setRawHeader("X-SOMETHING","blah"); QNetworkReply *nrpReply=oaFlow->networkAccessManager()->get(nrqRequest);
I don't like having to create a QNetworkRequest myself, but for a one-time use, it's fine.
Also, at this point I already had created a custom QNetworkAccessManager re-implementing createRequest() and including some methods to add/remove raw headers. And then used QAbstractOAuth::setNetworkAccessManager() to link it to the authorized object.