【问题标题】:C++ Consume API REST with Casablanca and POST XMLC++ 使用 Casablanca 和 POST XML 使用 API REST
【发布时间】: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


    【解决方案1】:

    我更改了库。使用 libcurl 没问题,而且更简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 2016-11-07
      相关资源
      最近更新 更多