Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. lcurl and JSON issue
Forum Updated to NodeBB v4.3 + New Features

lcurl and JSON issue

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 4 Posters 299 Views 2 Watching
  • 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.
  • T Offline
    T Offline
    timroberts
    wrote on last edited by
    #1

    Hello,

    I'm having an issue with lcurl and pushing JSON data up to a server. When I'm pushing the data to the server, I can see in the server logs that the data is arriving with all of the double quotes escaped with a back slash: \".

    The JSON data is fairly simple:

    {
          "page": 1,
         "page_data_size": 1000,
        "page_data_complete": false
    }
    

    this is arriving like

    {
        \"page\": 1,
        \"page_data_size\": 1000,
        \"page_data_complete\": false
    }
    

    My data string is using QJSONDocument into a QByteArray. I've checked over the QByteArray and there is no single backslash '\' in the QByteArray so it is something that the curl library is doing to my data.

    Pushing the data manually from the command line using curl or using a web service like postman does not arrive like this.

    Does anyone know what I can do here?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show the code you use to pass the QByteArray to libcurl ?

      Out of curiosity, why not use QNAM to send the data ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      piervalliP 1 Reply Last reply
      0
      • T Offline
        T Offline
        timroberts
        wrote on last edited by
        #3

        In short, legacy software, I'm stuck using libcurl.

        Good news though! I found the issue. It's a simple fix for anyone else that may run into the same issue.

        The issue was part of the headers were missing.

        struct curl_slist *chunk = NULL;
        chunk = curl_slist_append(chunk, "Content-Type: application/json");
        ccCurlErrorCode = curl_easy_setopt(curl,CURLOPT_HTTPHEADER,chunk);
        

        I have other code in the header, but this is the relevant flag. Without the Content-Type flag, libcurl defaults to URL encoding and the server was interpreting it as such. All is good now!

        1 Reply Last reply
        0
        • T timroberts has marked this topic as solved on
        • SGaistS SGaist

          Hi,

          Can you show the code you use to pass the QByteArray to libcurl ?

          Out of curiosity, why not use QNAM to send the data ?

          piervalliP Offline
          piervalliP Offline
          piervalli
          wrote on last edited by
          #4

          @SGaist
          I use lcurl instead of QNAM, because I am sure that there is a single post (request to server) instead with QNAM there more transmissios with problems on network.

          Christian EhrlicherC 1 Reply Last reply
          0
          • piervalliP piervalli

            @SGaist
            I use lcurl instead of QNAM, because I am sure that there is a single post (request to server) instead with QNAM there more transmissios with problems on network.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @piervalli said in lcurl and JSON issue:

            I use lcurl instead of QNAM, because I am sure that there is a single post (request to server) instead with QNAM

            I doubt this...

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved