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. Getting the QNetworkRequest right
Forum Updated to NodeBB v4.3 + New Features

Getting the QNetworkRequest right

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 5.1k Views 3 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.
  • S Offline
    S Offline
    shaan7
    wrote on last edited by
    #5

    I wasn't talking about --header, what I meant was that using ContentTypeHeader sets the Content-Type header, not Accept (which is mentioned in the curl example that you've told it works).

    @mikeosoft said in Getting the QNetworkRequest right:

    My assumption is that if I add the header elements to the QNetworkrequest object, the object will take care of formating them/building the request correctly.

    That is correct.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mikeosoft
      wrote on last edited by mikeosoft
      #6

      Yes, that was a good observation, but I'm afraid it doesn't work. I started off using the Accept version and then tried converting from the raw type to the standard type to see if that work. I just tried it again and I still get exactly the same response.

      request.setRawHeader("Accept", "application/json");
      

      Thanks for that.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        shaan7
        wrote on last edited by
        #7

        Try this for debugging, make a GET call to https://httpbin.org/headers which will respond back with the headers that you sent it. See if they look right.

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

          Hi,

          Which version of OpenSSL do you have installed on your system ?
          Do you get the same problem if you use your distribution provided Qt ?

          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
          1
          • M Offline
            M Offline
            mikeosoft
            wrote on last edited by
            #9

            I got prompted for an upgrade to Qt Creator 4.6.0 this morning, so I'm now using that.

            Trying the link to get the headers, gets me this, which to me look right in that it is formatted correctly and includes the 3 elements that I was specifically adding to the header.

            {
              "headers": {
                "Accept": "application/json", 
                "Accept-Encoding": "gzip, deflate", 
                "Accept-Language": "en-GB,*", 
                "App-Id": "5f5ddfdd", 
                "App-Key": "a4a5410cea52a716086abae4563cb4", 
                "Connection": "close", 
                "Host": "httpbin.org", 
                "User-Agent": "Mozilla/5.0"
              }
            }
            

            Thanks for suggesting that link it was useful.

            The OpenSSL version is:
            OpenSSL 1.0.2g 1 Mar 2016

            I'll try it with distribution version of Qt shortly and let you know what happens.

            A number of people who reported this error were using CORS, which I assume I'm not using can you confirm that I'm not, just to eliminate that?

            Thank you both of you.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mikeosoft
              wrote on last edited by
              #10

              If I install the default version, which is Qt 5.9.1 with QT Creator 4.3.1 In my working machine I get the error

              /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.10' not found

              I have been trying with a Virtual Machine, but Kubuntu seems to be a bit unstable and is giving me problems.

              I installed it a little while ago after moving from Mint because they are giving up on KDE. On my desktop machine it has been very unstable, locking up if leaving it for a short period. It appears to relate to the graphics and I have tried every graphic driver variation and am currently using the one that worked the best.

              I didn't have these problems with my laptop, but both seem to have a problem when you build a virtual-box virtual machine, it switches into an error screen resulting from a know Ubuntu error, which has a fix and tells you how to get out of it, but that doesn't work on these Virtual Machines. Which means I can't progress with building virtual machines to test this on.

              Mint as a Ubuntu derivative also had the known error with the screen locking, but the fix took you straight out of the situation.

              As I'm a bit stuck with that approach, do you have any other suggestions I can try.

              Thanks.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shaan7
                wrote on last edited by
                #11

                You might want to try KDE Neon although I really doubt your distribution is the problem here. If you are completely sure that the curl command line you originally posted still works then you should also point curl to https://httpbin.org/headers and compare the differences.
                I really doubt CORS is the issue because you're not adding any Origin: headers in your curl command line and you claim it still works.

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  mikeosoft
                  wrote on last edited by
                  #12

                  Other than the User-Agent, which would be different because they are different tools these two were present in the Qt generated version, but not in the curl version.

                  "Accept-Encoding": "gzip, deflate", 
                  "Accept-Language": "en-GB,*", 
                  

                  I tried adding both the additional headers to the curl command and got the warning messages below, followed by the correct Json response. I tried each header individually and both at the same time.

                  curl: (6) Could not resolve host: en-GB,*
                  curl: (6) Could not resolve host: gzip, deflate

                  Neither stopped it happening with curl, but they do seem to stop the Qt version.

                  I looked for ways to remove these header elements and it looks like QNetworkRequest won't let you do it. See bug QTBUG-9463.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mikeosoft
                    wrote on last edited by
                    #13

                    I tried live booting from a KDE Neon DVD and running my debug executable from my SSD and the error was the same as when booting from my installed Kubuntu.

                    I am keen to stay with a Ubuntu based distribution because of a number of other tools that I couldn't get to work in opensuse tumbleweed and KAOS when I tried them from those distros.

                    S 1 Reply Last reply
                    0
                    • M mikeosoft

                      I tried live booting from a KDE Neon DVD and running my debug executable from my SSD and the error was the same as when booting from my installed Kubuntu.

                      I am keen to stay with a Ubuntu based distribution because of a number of other tools that I couldn't get to work in opensuse tumbleweed and KAOS when I tried them from those distros.

                      S Offline
                      S Offline
                      shaan7
                      wrote on last edited by
                      #14

                      @mikeosoft said in Getting the QNetworkRequest right:

                      I am keen to stay with a Ubuntu based distribution

                      KDE Neon is based on Ubuntu :P

                      But in any case, as I said earlier, I doubt your problem is the distro.

                      1 Reply Last reply
                      1

                      • Login

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