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. [solved] Trouble getting JSON response with QNetworkRequest

[solved] Trouble getting JSON response with QNetworkRequest

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.0k Views
  • 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.
  • R Offline
    R Offline
    reactive
    wrote on last edited by
    #1

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

    The code is just

    @
    QNetworkRequest req;
    req.setUrl(QUrl("http://foo/..."));
    req.setRawHeader("Accept", "...")
    QNetworkReply* reply = manager->post(request, "")
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      Ummm.... You get JSON error as I understood, can you give more information? Raw response for example.

      --
      Vasiliy

      1 Reply Last reply
      0
      • R Offline
        R Offline
        reactive
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          Ok, how do you set "Accept" header in firefox?
          Do you sure firefox not send any more data to server (cookie as example)?

          --
          Vasiliy

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Use wireshark to do a packet capture and compare your app with firefox to see what is different in the request.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • R Offline
              R Offline
              reactive
              wrote on last edited by
              #6

              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!

              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