0
I’m wondering how do I send one post in format json
using a form.
That’s the form that 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 the 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, already tested with the postman and when I send an object like this :
{"carro":
{
"descricao":"um carro",
"nome":"fiat",
"tipo":"3-portas",
"urlFoto":"www.foto",
"urlVideo":"ww.video"
}
}
He accepts it perfectly, but when I do the post using form present:
HTTP Status 415 - Unsupported Media Type
I don’t know where I’m going wrong, or if there’s one missing jar that makes the conversion into a car object. I am using the jersey, just to remind.
You’re ordering by ajax?
– StillBuggin
No, I’m just doing it this way, the jersey should take this post and create the object. but my doubt is whether only with this is right or I’ll have to do as a few examples I saw that was with ajax using jquery. abrss
– micael