[英]Can't get the payload of a POST Request in Jersey
我需要恢复表单POST请求的整个有效负载,然后将其发送回接收方(PayPal将此作为验证过程)。 我尝试了几种方法,但始终收到相同的警告,没有有效负载:
Warning: A servlet request to the URI http://localhost:8080/ipnlistener contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
这是侦听器的代码
@POST
@Path("/ipnlistener")
public Response testIpn(String t) {
System.out.println(t);
return Response.ok().build();
}
我尝试添加不同的Consumes
批注,但没有任何变化。 当然,有了FormParam
批注,我可以检索单个字段,但是我确实需要整个请求。
我也尝试了以下
public Response testIpn(@Context HttpServletRequest req) throws IOException {
BufferedReader reader= req.getReader();
String sCurrentLine;
while ((sCurrentLine = reader.readLine()) != null) {
System.out.println(sCurrentLine);
}
return Response.ok().build();
}
但我得到了错误
getInputStream() has already been called for this request
我认为您可以将以下代码添加到文件中:
@Context
private HttpServletRequest request;
HttpServletRequest
包含请求的整个内容!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.