我正在尝试使用 C++ REST SDK (Casablanca) 库执行 POST HTTP 请求,但我没有成功......我也找不到任何最近/工作片段。有谁能够帮助我?
使用我的以下代码,我获得了一个运行时web::json::json_exception说“不是字符串”:
json::value postData;
postData[L"name"] = json::value::string(L"Joe Smith");
postData[L"sport"] = json::value::string(L"Baseball");
web::http::client::http_client client(L"https://jsonplaceholder.typicode.com/posts");
try
{
client.request(
methods::POST,
L"",
postData/*.as_string().c_str()*/,
L"application/json");
}
catch (web::json::json_exception &je)
{
std::cout << je.what();
}
catch (std::exception &e)
{
std::cout << e.what();
}
Run Code Online (Sandbox Code Playgroud)