Gateway 获取 RequestBody
百度搜了一大堆文献,全部什么改源码,封装Body啥的,都很复杂,这里直接利用的 Gateway 源码中的 CacheRequestBodyGatewayFilterFactory 缓存了RequestBody,我们先让它执行,然后执行我们的逻辑,即可直接取出RequestBody。
Gateway版本:
org.springframework.cloud:spring-cloud-starter-gateway:3.1.1
直接上代码:
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.react
版权声明:本文为qq_43630650原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。