[erlang-questions] [erlang-question][cowboy] Why got 415 unsupported media type when using POST method
寂寂
44290016@REDACTED
Fri Apr 10 03:30:52 CEST 2015
Dear All,
If I use GET method the REST API work properly, but when I change to POST, got 415 error
My code:
-export([init/2]).
-export([allowed_methods/2, content_types_provided/2]).
-export([to_json/2]).
init(Req, Opts) ->
{cowboy_rest, Req, Opts}.
allowed_methods(Req, State) ->
{[<<"POST">>], Req, State}.
content_types_provided(Req, State) ->
{[
{<<"application/json">>, to_json}
], Req, State}.
to_json(Req, State) ->
.....
when I test the REST API I:
curl http://192.168.1.103:8080/cloud_init -v -XPOST -H"Content-Type: application/json" -d '{"client_id": "4342jltj3i"}'
got :
* Hostname was NOT found in DNS cache
* Trying 192.168.1.103...
* Connected to 192.168.1.103 (192.168.1.103) port 8080 (#0)
> POST /cloudbox_init HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 192.168.1.103:8080
> Accept: */*
> content-type: application/json
> Content-Length: 28
>
* upload completely sent off: 28 out of 28 bytes
< HTTP/1.1 415 Unsupported Media Type
< connection: keep-alive
* Server Cowboy is not blacklisted
< server: Cowboy
< date: Fri, 10 Apr 2015 00:56:15 GMT
< content-length: 0
< content-type: application/json
<
* Connection #0 to host 192.168.1.103 left intact
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150410/6cf8af5e/attachment.htm>
More information about the erlang-questions
mailing list