charset
当在标头中指定属性时,Jersey 2.0(使用 servlet 3.1)似乎无法解码参数Content-Type
。
例如考虑以下端点:
@POST
@Path("/hello")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response hello(@FormParam("name") String name) {
System.out.println(name);
return ok();
}
此 curl 请求有效:
curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "name=tom" http://localhost:8080/sampleapp/hello
相反,以下请求不起作用,name
参数为null
:
curl -X POST -H "content-type: application/x-www-form-urlencoded; charset=UTF-8" -d "name=tom" http://localhost:8080/sampleapp/hello
我认为charset=UTF-8
内容类型中的添加会破坏我的代码。
编辑:
我已经打开了一张官方票,以防万一这是一个错误:https ://java.net/jira/browse/JERSEY-1978