gpt4 book ai didi

rest - 如何修复 Jersey POST 请求参数警告?

转载 作者:行者123 更新时间:2023-12-03 07:50:52 26 4
gpt4 key购买 nike

我正在使用 Jersey 构建一个非常简单的 REST API,我的日志文件中有一个我不确定的警告。

WARNING: A servlet POST request, to the URI http://myserver/mycontext/myapi/users/12345?action=delete, 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.



我的 webapp 只定义了 Jersey servlet,映射到/myapi/*

我怎样才能停止这些警告?

最佳答案

对我来说,警告是针对 POST application/x-www-form-urlencoded 显示的。我正在使用 Spring Boot,它有一个 HiddenHttpMethodFilter,它在其他任何事情之前先执行 getParameter ......所以我最终做了这个讨厌的覆盖:

@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if ("POST".equals(request.getMethod())
&& request.getContentType().equals(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
filterChain.doFilter(request, response);
} else {
super.doFilterInternal(request, response, filterChain);
}
}
};
}

关于rest - 如何修复 Jersey POST 请求参数警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2011895/

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