Solved QNetworkAccessManager / QNetworkRequest gets different response than CURL
-
Hallo,
I am writing a Plugin to Jira via REST API.
Now I am trying to download an Attachment
CURL
c:\portable\curl\curl-7.71.0-win64-mingw\bin>curl.exe -D- -X GET -H "Authorization: Basic ENCODED_STRING_CENSORED" https://XXXX.atlassian.net/secure/attachment/10000/overqualified.jpg.webp HTTP/2 302 server: AtlassianProxy/1.15.8.1 cache-control: no-cache, no-store, must-revalidate content-type: image/webp strict-transport-security: max-age=315360000; includeSubDomains; preload date: Sat, 29 Aug 2020 01:32:27 GMT atl-traceid: XXX x-arequestid:XXX x-aaccountid: XXX location: https://api.media.atlassian.com/CENSORED_FOR_SECURITY=overqualified.jpg.webp expires: Thu, 01 Jan 1970 01:59:59 EET pragma: no-cache x-xss-protection: 1; mode=block timing-allow-origin: * x-content-type-options: nosniff micros-issuer: micros/edge-authenticator set-cookie: XXXX expect-ct: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400 content-length: 0
Now my Code with QT
QByteArray JiraWidget::downloadAttachment(const QString& Url, JWidget* sender) { auto* man = new QNetworkAccessManager(); connect(man, &QNetworkAccessManager::finished, &this->synchronous, &QEventLoop::quit); auto req = QNetworkRequest(QUrl(url)); //req.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "image/webp"); //req.setRawHeader("Accept", "image/webp"); req.setRawHeader("Authorization", "Basic " + this->authArray.toBase64()); auto* reply = man->get(req); this->synchronous.exec(); while (!reply->isFinished()) std::this_thread::sleep_for(std::chrono::milliseconds(500)); auto code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); auto error = reply->errorString(); auto resp = reply->readAll(); auto loc = reply->rawHeaderList(); for (auto& arr : loc) { qDebug() << arr; qDebug() << reply->rawHeader(arr); int i = 0; } delete man; return resp; }
Gets as Header
Content-Type: text/html;charset=UTF-8and location is /secure/MyJiraHome.jspa
Why is CURL retrieving the correct location while my Application fails?
-
Use wireshark, take a look what curl and Qt really sends as request.
Why do you block the ui for such stuff?
-
Hi,
Beside @Christian-Ehrlicher point, are you getting any redirection ?
-
@Christian-Ehrlicher said in QNetworkAccessManager / QNetworkRequest gets different response than CURL:
Use wireshark, take a look what curl and Qt really sends as request.
Why do you block the ui for such stuff?
By looking the code on this Forum I found the typo responsible for the behaviour.
I should move the Download stuff into a new Thread.
synchronous Download is more comfortable in this situation. -
@QtCoder87 said in QNetworkAccessManager / QNetworkRequest gets different response than CURL:
I should move the Download stuff into a new Thread.
synchronous Download is more comfortable in this situation.This contradicts itself ...