Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] Trouble getting JSON response with QNetworkRequest

    General and Desktop
    3
    6
    6716
    Loading More Posts
    • 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
      reactive 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-Alive

      The code is just

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

      1 Reply Last reply Reply Quote 0
      • V
        vsorokin last edited by

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

        --
        Vasiliy

        1 Reply Last reply Reply Quote 0
        • R
          reactive 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.

          1 Reply Last reply Reply Quote 0
          • V
            vsorokin 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)?

            --
            Vasiliy

            1 Reply Last reply Reply Quote 0
            • Z
              ZapB last edited by

              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 Reply Quote 0
              • R
                reactive 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!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post