最佳答案
根据答案 用 Spring@Controller 解决 x-www-form-urlencode 的问题
我已经编写了下面的@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");
}
}
请求失败,并出现以下错误
{
"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": "/users/usermail%40gmail.com/authenticate"
}
[附注: 泽西人更友好,但是由于这里的实际限制现在不能使用它]