ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.46k stars 889 forks source link

Trying to Convert application/x-www-form-urlencoded Req.Body to JSON #356

Closed benmaxlevy closed 4 years ago

benmaxlevy commented 4 years ago

Hi, I'm trying to convert application/x-www-form-urlencoded req.body into JSON. I've tried this:

CROW_ROUTE(app, "/register").methods("POST"_method)([](const request& req){
        auto x = crow::json::load(req.body);
        auto str = crow::json::dump(x);
        return str;
});

But, it doesn't work, which makes sense. 1) How can I parse application/x-www-form-urlencoded into JSON? or 2) How can I convert the req.body to std::string, so that I can "manually" convert it into JSON? or 3) How can I send a POST request from a form (HTML)? (Note: application/json isn't integrated into HTML yet).

Thank you so much, all!

benmaxlevy commented 4 years ago

Figured out. First, convert the req.body into a string that is json, then do the auto x = load(req.body).