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. QNetworkAccessManager / QNetworkRequest gets different response than CURL
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager / QNetworkRequest gets different response than CURL

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 423 Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    QtCoder87
    wrote on last edited by
    #1

    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-8

    and location is /secure/MyJiraHome.jspa

    Why is CURL retrieving the correct location while my Application fails?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use wireshark, take a look what curl and Qt really sends as request.

      Why do you block the ui for such stuff?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Q 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Beside @Christian-Ehrlicher point, are you getting any redirection ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Use wireshark, take a look what curl and Qt really sends as request.

          Why do you block the ui for such stuff?

          Q Offline
          Q Offline
          QtCoder87
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0

            • Login

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