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?

链接地址: http://www.djcxy.com/p/8622.html

上一篇: 数据使用cURL到API

下一篇: LibCurl似乎逃脱了我的POSTFIELDS