Sulla base della risposta for problem with x-www-form-urlencoded with Spring @ControllerTipo di contenuto 'application/x-www-form-urlencoded; charset = UTF-8' non supportato per @RequestBody MultiValueMap
ho scritto il seguito metodo @Controller
@RequestMapping(value = "/{email}/authenticate", method = RequestMethod.POST
, produces = {"application/json", "application/xml"}
, consumes = {"application/x-www-form-urlencoded"}
)
public
@ResponseBody
Representation authenticate(@PathVariable("email") String anEmailAddress,
@RequestBody MultiValueMap paramMap)
throws Exception {
if(paramMap == null && paramMap.get("password") == null) {
throw new IllegalArgumentException("Password not provided");
}
}
la richiesta a cui non riesce con l'errore sotto
{
"timestamp": 1447911866786,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "https://stackoverflow.com/users/usermail%40gmail.com/authenticate"
}
[PS: Jersey era molto più gentile, ma non ha potuto usarlo ora date le restrizioni pratiche qui]
Forse si aggiunge consuma = { "application/x-www-form-urlencoded"} in @RequestBody? – shiladitya
Come hai eseguito la richiesta? aggiungi il codice di (js, jquery, arricciatura o qualsiasi altra cosa tu usi). –
Ho lo stesso problema. Nel mio caso uso jquery ajax per pubblicare i dati e il dato è 'JSON.stringify ({" ordersToDownload ":" 00417002 "}' – Arashsoft