I'm wondering how do I send a post
in the format json
using form
.
This is the form
I use:
<form action="rest/carros" enctype='application/json' accept-charset="utf-8" method="post">
<input name='carro[descricacao]' value='carro de form'/>
<input name='carro[nome]' value='citroen'/>
<input name='carro[tipo]' value='4-portas'/>
<input name='carro[urlFoto]' value='www.foto'/>
<input name='carro[urlVideo]' value='www.video'/>
<input type="submit" value='enviar'/>
</form>
This is the method that receives post
:
@POST
@Consumes(MediaType.APPLICATION_JSON + "; charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + "; charset=utf-8")
public String salvarCarro(Carro c){
business.salvarCarro(c);
return "salvo";
}
Everything is working normal, I already tested with postman
and when I send an object like this:
{"carro":
{
"descricao":"um carro",
"nome":"fiat",
"tipo":"3-portas",
"urlFoto":"www.foto",
"urlVideo":"ww.video"
}
}
It accepts perfectly, but when I do post
using form
it displays:
HTTP Status 415 - Unsupported Media Type
I do not know where I'm going wrong, or if I do not have jar
to convert to a car object. I'm using jersey
, just to remember.