LibCurl似乎逃脱了我的POSTFIELDS

LibCurl seems to escape my POSTFIELDS

本文关键字:我的 POSTFIELDS 逃脱 LibCurl      更新时间:2023-10-16

我使用此代码将json发布到服务器:

但CURL似乎在某种程度上逃脱了数据,即将其转换为"{\"电子邮件\":\"test@example.se\"}"(使我的引号转义)。我认为curl发布的内容类型仍然是"application/x-www-form-urlencoded",即使是你,我也在标题中用application/json覆盖了它。我怎么能让卷发不那样做?

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);

从这里开始:http://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html

libcurl不会以任何方式为您转换或编码它。

指向的数据不会被库复制:因此,它必须由调用应用程序保留,直到相关的传输完成。

你确定你在遵守这些通知吗?