#c #cpprest-sdk
#c #cpprest-sdk
Вопрос:
Я отправил сообщение в формате json с помощью curl, но я не могу прочитать его с сервера. В чем проблема?
void Handler::handle_post(http_request request){
std::cout << request.to_string() << std::endl;
auto j = json::value::object();
request.extract_json().then([amp;j](pplx::task<json::value> task) {
try{
auto const amp; jvalue = task.get();
for (auto const amp; e : jvalue.as_array())
{
if (e.is_string())
{
auto key = e.as_string();
std::cout << key << std::endl;
}
}
}
catch (http_exception const amp; 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
запрос сервера:
Если информации недостаточно, я покажу вам полный код.