fix 修复 WebFluxUtils 读取空 body 报 null 问题

2.X
疯狂的狮子Li 2 years ago
parent bf89a9d416
commit 75e175f7f3

@ -1,5 +1,6 @@
package com.ruoyi.gateway.utils;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.JsonUtils;
import com.ruoyi.common.core.utils.StringUtils;
@ -79,7 +80,11 @@ public class WebFluxUtils {
* @return body
*/
public static String resolveBodyFromCacheRequest(ServerWebExchange exchange) {
DataBuffer buffer = (DataBuffer) exchange.getAttributes().get(ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR);
Object obj = exchange.getAttributes().get(ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR);
if (ObjectUtil.isNull(obj)) {
return null;
}
DataBuffer buffer = (DataBuffer) obj;
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer());
return charBuffer.toString();
}

Loading…
Cancel
Save