[solved] Trouble getting JSON response with QNetworkRequest
-
wrote on 28 Jun 2011, 14:44 last edited by
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, "")
@ -
wrote on 28 Jun 2011, 15:18 last edited by
Ummm.... You get JSON error as I understood, can you give more information? Raw response for example.
-
wrote on 28 Jun 2011, 19:59 last edited by
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. -
wrote on 28 Jun 2011, 20:06 last edited by
Ok, how do you set "Accept" header in firefox?
Do you sure firefox not send any more data to server (cookie as example)? -
wrote on 28 Jun 2011, 20:07 last edited by
Use wireshark to do a packet capture and compare your app with firefox to see what is different in the request.
-
wrote on 28 Jun 2011, 21:04 last edited by
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!
6/6