I sent a json POST with curl, but I can't read it from the server. What is the problem?
void Handler::handle_post(http_request request){
std::cout << request.to_string() << std::endl;
auto j = json::value::object();
request.extract_json().then([&j](pplx::task<json::value> task) {
try{
auto const & jvalue = task.get();
for (auto const & e : jvalue.as_array())
{
if (e.is_string())
{
auto key = e.as_string();
std::cout << key << std::endl;
}
}
}
catch (http_exception const & e)
{
std::cout << e.what() << std::endl;
std::cout << "hi" << std::endl;
}
}).wait();
request.reply(status_codes::OK);
}
curl :
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:10022
server request:
If there is insufficient information, I will show you the full code.