What am I doing wrong?
I am trying to use POST data but always do not work. So, how do you get the first response to the conditional descriptor badRequest ("Expceting some data") to be zero .
Routes
POST /pedidos/novo controllers.Pedidos.cadastraPedidoNoBanco
Action in my controller
@BodyParser.Of(BodyParser.Json.class)
public static Result cadastraPedidoNoBanco(){
JsonNode data = request().body().asJson();
if(data == null){
return badRequest("Expceting some data");
} else {
return ok(data);
}
}
Another failure test
So this did not happen, but I did not know why the answer is this:
Source
public static Result cadastraPedidoNoBanco(){
Map<String,String[]> data = request().body().asFormUrlEncoded();
if(data == null){
return badRequest("Expceting some data");
} else {
String response = "";
for(Map.Entry value : data.entrySet()){
response += "\n" + value.getValue();
}
return ok(response);
}
}
Answer
[Ljava.lang.String;@5817f93f
[Ljava.lang.String;@decc448
[Ljava.lang.String;@334a5a1c
[Ljava.lang.String;@5661fe92
[Ljava.lang.String;@3b904f8c
[Ljava.lang.String;@7f568ee0
[Ljava.lang.String;@bbe5570
Curl
curl "http://localhost:9000/pedidos/novo" -H "Origin: http://localhost:9000" -H "Accept-Encoding: gzip,deflate" -H "Accept-Language: en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4" -H "User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: max-age=0" -H "Referer: http://localhost:9000/pedidos/novo" -H "Connection: keep-alive" -H "DNT: 1" --data "nome_cliente=nj&telefone_cliente=jn&rua_cliente=jkn&num_cliente=kjn&comp_cliente=kjn&cep_cliente=kjn&bairro_cliente=jnk" --compressed
source
share