Curlpp 和 PUT 请求

Curlpp and PUT request

如何使用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(); 

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

您需要指定 PUT 方法

request.setOpt(new curlpp::options::CustomRequest{"PUT"});

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