[solved] Trouble getting JSON response with QNetworkRequest
-
I successfully used QNetworkRequest to connect to a SOAP service and a website that returns its result in the html text.
But when I try to connect to a service that returns JSON text I get an error (from them I'm assuming): "status" : error, "message" : "invalid format of ___ field". The same url http://foo/?user=abc&pass=123&field=foo works fine in Firefox.
The only fields I'm setting in the header are: Accept = application/json text/* and Connection = Keep-AliveThe code is just
@
QNetworkRequest req;
req.setUrl(QUrl("http://foo/..."));
req.setRawHeader("Accept", "...")
QNetworkReply* reply = manager->post(request, "")
@ -
By "raw response" do you just mean the text I am getting back?
It is: { “status” : error, “message” : “invalid format of ___ field” } (I've taken out the field name).When I enter the URL into Firefox I get a "Save as" dialog to save the json data and
it works fine. -
I got it to work! I was reusing the code I wrote for the SOAP service so I had:
@ manager->post(request, "") @I changed it to @ manager->get(request) @ and that did the trick.
(Also, apparently the url parameters are case sensitive, though that wasn't the original issue.)EDIT: And of course, thanks to everyone!