lcurl and JSON issue
-
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?
-
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 ?
-
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!
-
-
@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...