c++casablancacpprest-sdk

List to form-encoded parameters in Casablanca


I am using cpprestsdk (casabalanca) to POST a request to a server and I have a list of parameters

std::list<std::pair<string, string>> query;
query.push_back(std::make_pair("val1", "one two"));
query.push_back(std::make_pair("val2", "yo"));

that needs to be encoded as form-encoded parameters.

val1=one%20two&val2=yo

The problem I cannot find a Api to do that (like I have web::json::value for a json payload). I need to encode each key/value and do the concatenation myself. There is an Api I am missing out or this simply doesn't exist ?


Solution

  • Found the solution...

    web::http::http_request request;
    
    web::uri_builder parameter;
    parameter.append_query("val1", "one two", true);
    parameter.append_query("val2", "yo", true);
    
    request.set_body(parameter.query(), web::http::details::mime_types::application_x_www_form_urlencoded);