Getting the QNetworkRequest right
-
I wasn't talking about
--header
, what I meant was that usingContentTypeHeader
sets theContent-Type
header, notAccept
(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.
-
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.
-
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.
-
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 ? -
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 2016I'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.
-
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.
-
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 pointcurl
to https://httpbin.org/headers and compare the differences.
I really doubt CORS is the issue because you're not adding anyOrigin:
headers in yourcurl
command line and you claim it still works. -
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, deflateNeither 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.
-
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.
-
@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.