SpringCloudGateway读取、修改请求体(modify SpringCloudGateway request body)
在Spring Cloud Gateway中,读取Get请求的参数并非一件很难的事,但是读取Post请求的请求体(body)也并非一件简单事。 说明 Spring官方虽然提供了预言类: ReadBodyPredicateFactory (谓词工厂)、ModifyRequestBodyGatewayFilterFactory (过滤器工厂), 但仍然是 bate 版,并没有直接实现获取 request body 的 filter,所以如果想要读取request body,需要参考以上两个预言类,自行实现filter。 实现方式 首先,实现一个CacheRequestBodyFilter用来将request body读取出来并存到exchange的自定义属性中: package ltd.lemontech.contractor.gateway.