简体   繁体   中英

LibCurl seems to escape my POSTFIELDS

I'm using this code to post json to a server:

But it seems like CURL somewhere in the way escapes the data, ie transforms it into "{\\"email\\":\\"test@example.se\\"}" (Makes my quotes escaped). I think curl still posts with the Content-Type "application/x-www-form-urlencoded", even thou I've overwritten it with application/json in my headers. How can I make curl not do that?

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
const std::string& data = "{\"email\":\"test@example.se\"}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str() );
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.size() );
// Headers
curl_easy_setopt(headers, "Content-Type: application/json");
curl_easy_setopt(headers, "Authorization: Basic: something:something");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);

From here: http://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html

libcurl will not convert or encode it for you in any way.

The data pointed to is NOT copied by the library: as a consequence, it must be preserved by the calling application until the associated transfer finishes.

Are you sure you are following these notices?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM