首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++使用Casablanca和POST XML

C++使用Casablanca和POST XML
EN

Stack Overflow用户
提问于 2018-01-22 19:11:53
回答 1查看 351关注 0票数 0

问题是如何使用需要在主体类型XML和headers参数上发布内容的API REST。我只找到了使用JSON的解决方案。

代码语言:javascript
复制
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;
});

感谢大家!

EN

回答 1

Stack Overflow用户

发布于 2018-01-31 17:17:49

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48380240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档