Search code examples
putcurlpp

Curlpp and PUT request


How to send PUT request using curlpp library? I found out how to send http POST (example below) or GET request, but nothing for PUT request.

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(); 

Solution

  • I had the exact same question and found the solution when looking for the way to do it using libcurl, see Send string in PUT request with libcurl.

    You need to specify the PUT method with

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

    the other required options are the same as with to the POST method.