如何在Spring Boot控制器中获取原始POST数据

问题描述 投票:1回答:1

我有一个简单的控制器类extends AbstractController,我通过创建一个新的SimpleUrlHandlerMapping bean插入Spring的处理程序映射机制。

在我的课堂上,我需要阅读原始的POST数据,即使Content-Type是application/x-www-form-urlencoded。这在Servlet规范中有点棘手,因为为了做到这一点,你需要在访问任何request.getInputStream()方法之前调用request.getReader()request.getParameter*()。否则,后者将消耗输入流,它将不再可用。

在我的班级中,我没有调用任何getParameter*()方法,但是当Content-Type是application/x-www-form-urlencoded时,我仍然看到一个空的请求体。这意味着Spring在处理对我的类的控制之前调用了一个getParameter*()方法。

哪个班级正在做这个,我该如何预防呢?


(注意过度热心的编辑:这个问题特定于Spring Boot。它不是其他“原始POST数据”问题的重复。)

spring-boot post urlencode
1个回答
1
投票

找到了。

我只需要禁用HiddenHttpMethodFilter,我不会使用它:

spring.mvc.hiddenmethod.filter.enabled=false
© www.soinside.com 2019 - 2024. All rights reserved.