Curlpp和PUT请求

时间:2017-11-28 08:47:15

标签: put curlpp

如何使用curlpp库发送PUT请求?我发现了如何发送http POST(下面的示例)或GET请求,但没有PUT请求。

curlpp::Cleanup cleaner;
curlpp::Easy request;

request.setOpt(new curlpp::options::Url(url));
curlpp::types::WriteFunctionFunctor functor(WriteMemoryCallback);
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
request.setOpt(test);

std::list<std::string> header;
header.push_back("Content-Type: application/json");

request.setOpt(new curlpp::options::HttpHeader(header));
request.setOpt(new curlpp::options::PostFields(message));
request.perform(); 

1 个答案:

答案 0 :(得分:1)

我有完全相同的问题并在寻找使用libcurl的方法时找到了解决方案,请参阅Send string in PUT request with libcurl

您需要使用

指定PUT方法
request.setOpt(new curlpp::options::CustomRequest{"PUT"});

其他必需选项与POST方法相同。