简体   繁体   English

在Jersey中无法获取POST请求的有效负载

[英]Can't get the payload of a POST Request in Jersey

I need to recover the whole payload of a form POST request, to send it back to the receiver (PayPal requires this as a verification procedure). 我需要恢复表单POST请求的整个有效负载,然后将其发送回接收方(PayPal将此作为验证过程)。 I tried several ways but I always get the same warning, with no payload: 我尝试了几种方法,但始终收到相同的警告,没有有效负载:

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.

Here's the code of the listener 这是侦听器的代码

@POST
@Path("/ipnlistener")
public Response testIpn(String t) {  
   System.out.println(t);
   return Response.ok().build();
}

I tried to add different Consumes annotations but nothing changes. 我尝试添加不同的Consumes批注,但没有任何变化。 Of course with FormParam annotations I'm able to retrieve single fields, but I really need the whole body of the request. 当然,有了FormParam批注,我可以检索单个字段,但是我确实需要整个请求。

I also tried with the following 我也尝试了以下

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();
}

but I get the error 但我得到了错误

getInputStream() has already been called for this request

i think you can add the following code to your file: 我认为您可以将以下代码添加到文件中:

 @Context  
 private HttpServletRequest request; 

The HttpServletRequest contains the whole body of the request! HttpServletRequest包含请求的整个内容!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM