【发布时间】:2018-01-31 17:17:49
【问题描述】:
问题是如何使用需要在正文类型 XML 和标头参数上发布内容的 API REST。我发现只有 JSON 的解决方案。
return pplx::create_task([]
{
json::value postData;
postData[L"name"] = json::value::string(L"Joe Smith");
postData[L"hobby"] = json::value::string(L"Baseball");
http_client client(L"http://localhost:5540/api/values");
return client.request(methods::POST, L"",
postData.to_string().c_str(), L"application/xml");
}).then([](http_response response)
{
if (response.status_code() == status_codes::OK)
{
auto body = response.extract_string();
std::wcout << L"Added new Id: " << body.get().c_str() << std::endl;
return std::stoi(body.get().c_str());
}
return 0;
});
谢谢大家!
【问题讨论】:
标签: c++ xml rest casablanca