【发布时间】:2021-11-25 12:49:16
【问题描述】:
将数据发布到 zendesk 时,我所有的变音符号都保存为“?”人物。 postmann 应用程序中的同一篇文章运行良好。 我什至复制了整个 postman C - libcurl 代码,编译并启动它: 同样的结果,变音符号显示为问号。 postman 发布 json 和 visual studio 发布 json 有什么区别?
代码如下:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://xx.zendesk.com/api/v2/users/create_or_update.json");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "id: 1");
headers = curl_slist_append(headers, "Authorization: Basic eXaMpLe1234");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Cookie: __cfruid=2c9eb500bc16cc34cd7390604b24ece125e7e8ad-187187187");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{ \"user\": {\"external_id\": \"160102\", \"name\" : \"TestÜÄÖ\", \"phone\": \"014567-0\", \"user_fields\": { \"anrede\": \"Herr\"}, \"organization\":{\"name\":\"testorg\"}, \"email\" : \"\"} }";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
在 VS 中是否有一个配置,我必须在发布数据时告诉他我想要 utf-8 编码?
标题中的“charset utf-8”产生相同的结果
编辑:使用 windows cmd 发送具有相同数据的基本 curl 行为相同并将元音变音符号保存为问号,即使邮递员生成了当邮递员发送它时有效的 curl 语句。
【问题讨论】:
-
您的 C++ 文件本身是否以 UTF8 编码?您可能还想使用
u8字符串前缀告诉编译器为您将字符串转换为 UTF-8。 -
你就是那个男人! u8 前缀有效!
-
u8前缀对您有用,但实际上,我建议您确保所有源都编码为 UTF-8。
标签: c++ json character-encoding