URL 在 POST 网络服务中作为表单数据访问的数据
URL data accessed as form data in POST webservice
我的网络服务界面类似于
@Consumes("application/x-www-form-urlencoded")
@POST
@Path("/testCall/{id}")
Object testCall(@PathParam("id") String myId, @FormParam("formId") String formId, @Context HttpServletRequest request);
现在我将 Web 服务调用为 POST,并使用来自 REST 客户端的 URL
https://myTest.com/1.0/testCall/12345?formId=007
它工作正常。当我提到 formId
作为表单参数时,我不明白为什么它接受来自 URL 参数的数据?
@FormParam
的Javadoc对参数的来源很清楚:
Binds the value(s) of a form parameter contained within a request
entity body to a resource method parameter.
观察到的行为似乎有三种可能性:
- 请求内容也包含参数(你的情况不是)
- 实现有一个错误
- 请求内容已被过滤器消耗
JAX-RS spec,第 10.1 章。解释第三种可能性:
Servlet filters may trigger consumption of a request body by accessing
request parameters. In a servlet container the @FormParam annotation
and the standard entity provider for application/x-www-form-urlencoded MUST obtain their values from the servlet request
parameters if the request body has already been consumed. Servlet APIs
do not differentiate between parameters in the URI and body of a
request so URI-based query parameters may be included in the entity
parameter.
我的网络服务界面类似于
@Consumes("application/x-www-form-urlencoded")
@POST
@Path("/testCall/{id}")
Object testCall(@PathParam("id") String myId, @FormParam("formId") String formId, @Context HttpServletRequest request);
现在我将 Web 服务调用为 POST,并使用来自 REST 客户端的 URL
https://myTest.com/1.0/testCall/12345?formId=007
它工作正常。当我提到 formId
作为表单参数时,我不明白为什么它接受来自 URL 参数的数据?
@FormParam
的Javadoc对参数的来源很清楚:
Binds the value(s) of a form parameter contained within a request entity body to a resource method parameter.
观察到的行为似乎有三种可能性:
- 请求内容也包含参数(你的情况不是)
- 实现有一个错误
- 请求内容已被过滤器消耗
JAX-RS spec,第 10.1 章。解释第三种可能性:
Servlet filters may trigger consumption of a request body by accessing request parameters. In a servlet container the @FormParam annotation and the standard entity provider for application/x-www-form-urlencoded MUST obtain their values from the servlet request parameters if the request body has already been consumed. Servlet APIs do not differentiate between parameters in the URI and body of a request so URI-based query parameters may be included in the entity parameter.