c++ - C++ 发送形成和发送 JSON 结构并使用 CurlLib 发布
问题描述
当它只是一个带有“content = blahblah”的标准字符串时,这有效
所以我有我的 JSON 结构
{
"content": null,
"embeds": [
{
"title": "Login",
"description": "Key = null",
"color": null
}
]
}
我想我已经正确地将它放入 C++ JSON
json data;
data = R"(
{
"content": null,
"embeds": [
{
"title": "Login",
"description": "Key = null",
"color": null
}
]
}
)"_json;
我有我的 curl 代码,但这会引发异常。
if (curl) {
//Set URL that will be posted to
curl_easy_setopt(curl, CURLOPT_URL, webhookURL);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
//Set post data
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.dump().data());
//Get result
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
std::cout << curl_easy_strerror(res) << std::endl;
curl_easy_cleanup(curl);
}
}
curl_global_cleanup();
我再次更改了 cpp json,但我得到了一个不同的异常异常:
{"message": "Cannot send an empty message", "code": 50006}
请帮忙,谢谢
解决方案
推荐阅读
- pytorch - 为什么我的 GPU 在大量可用时无法使用?
- xml - 与文件夹结构的 SQL 同步
- c++ - 如果我有时间从纪元开始以毫秒为单位,如何将纪元以来的时间(以毫秒为单位)转换为人类可读的时间和日期
- mongodb - 卡在 MongoDB 中的嵌套分组
- ios - 唯一标识 iOS 中应用添加的照片库中的照片/视频 - Swift
- amazon-ec2 - 如何将 codedeploy 与 Bitbucket 集成
- terraform - 了解 Terraform for_each 循环迭代
- javascript - 切换一组选项卡时,为什么内容不会在点击时重新出现?
- angular - 角垫日历标题箭头事件
- c++ - 如何阻止变量符号被导出 macOS