有没有办法在Spring Boot中获得原始的帖子正文?

时间:2019-04-25 05:45:59

标签: java spring spring-boot slack slack-commands

我正在尝试在春季靴子2.1中verify a slack request。我可以在单元测试中正确计算哈希值。但是,当服务器处理实际请求时,我无法使验证工作。这是因为url参数的顺序在初始请求和调用控制器的时间之间发生了变化。

您可以使用示例控制器复制此内容,并在下面进行卷曲。请注意,curl中的表单有效负载为hello=world&foo=baz&two=three,响应重新排序为two=three&foo=baz&hello=world

理论

我相信这here正在发生。 Spring检测到表单数据已经过帐,然后对表单参数进行编码,然后将其写入新的输入流。似乎在迭代过程中对参数进行编码的地图没有保留原始顺序。

问题

有没有办法获得原始的邮件正文?


复制

@Controller
@ResponseBody
public class SlackController {
    @RequestMapping(
            path = "slack/command",
            method = RequestMethod.POST,
            produces = { MediaType.TEXT_PLAIN_VALUE },
            consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
    public String executeCommand(
            @RequestBody String requestBody
    ) {
        return requestBody;
    }
}
$ curl -X POST 'http://localhost:8080/slack/command' \
     -H 'Content-Type: application/x-www-form-urlencoded' \
     -H 'Accept: text/plain' \
     -d 'hello=world&foo=baz&two=three'

HTTP/1.1 200 OK
Date: Thu, 25 Apr 2019 05:26:53 GMT
Content-Type: application/json;charset=iso-8859-1
Content-Length: 29

two=three&foo=baz&hello=world

0 个答案:

没有答案
相关问题