这是json数据
{
"title": "The Title",
"content": "The Content"
}
curl -vX POST http://localhost:10003/sample -H "Content-Type:application/json" \ -d '{ "title": "The Title", "content": "The Content" }'
-export([content_types_accepted/2]).
allowed_methods(Req, State) ->
{[<<"GET">>, <<"POST">>], Req, State}.
content_types_accepted(Req, State) ->
{[{{<<"application">>, <<"json">>, []}, welcome}], Req, State}.
welcome(Req, State) ->
Req_method = cowboy_req:method(Req),
io:format("Req_method is ~p ~n", [Req_method]),
Req_Body = cowboy_req:body(Req),
io:format("Body is ~p ~n", [Req_Body]),
Body = <<"<h1>This is a response for other methods</h1>">>,
io:format("Body is ~p ~n",[Body]),
{Body, Req, State}.
我看到了 Method 和 Body,但试图捕获无法这样做的 json 数据。