NetworkAccessManager: Use QNetworkRequest::setHeader

This commit is contained in:
Jonas Kvinge 2024-03-24 06:58:33 +01:00
parent 4075f92eec
commit a0ea75b74e
1 changed files with 2 additions and 2 deletions

View File

@ -46,7 +46,7 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR
QByteArray user_agent;
if (request.hasRawHeader("User-Agent")) {
user_agent = request.rawHeader("User-Agent");
user_agent = request.header(QNetworkRequest::UserAgentHeader).toByteArray();
}
else {
user_agent = QString("%1 %2").arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion()).toUtf8();
@ -54,7 +54,7 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR
QNetworkRequest new_request(request);
new_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
new_request.setRawHeader("User-Agent", user_agent);
new_request.setHeader(QNetworkRequest::UserAgentHeader, user_agent);
if (op == QNetworkAccessManager::PostOperation && !new_request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
new_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");