gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:41:24 26 4
gpt4 key购买 nike

我需要恢复表单 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 包含请求的整个主体!

关于java - 无法在 Jersey 中获取 POST 请求的有效负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34867062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com