【发布时间】:2014-12-16 18:17:15
【问题描述】:
我正在使用此代码将 json 发布到服务器:
但似乎 CURL 以某种方式转义了数据,即将其转换为 "{\"email\":\"test@example.se\"}" (使我的引号转义)。 我认为 curl 仍然使用 Content-Type "application/x-www-form-urlencoded" 发布,即使你在我的标题中用 application/json 覆盖了它。 我怎样才能让 curl 不这样做?
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);
【问题讨论】:
-
libcurl 根本没有代码可以转义或转换该数据!
-
@DanielStenberg 考虑一下我认为服务器可能需要utf8而不是ansi。我明天上班先试试。