title: Get request body string from ServerHttpRequest / Flux<DataBuffer>
body: <p>I am using spring boot version - 2.0.6.RELEASE and spring cloud version - Finchley.SR2</p>
  
  <p>and i have created my custom gateway filter to modify the request body.</p>
  
  <p>but while converting the request body to string using Flux i am getting a empty string. i need a method to get the string corresponding to my request  body.</p>
  
  <pre><code>@Override
  public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
      ServerHttpRequest request = (ServerHttpRequest) exchange.getRequest();
      String s = resolveBodyFromRequest(request);
       /* s comes out to be "" */
      return chain.filter(newExchange);
  
  
  }
  
  
  
  private String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest){
      //Get the request body
      Flux&lt;DataBuffer&gt; body = serverHttpRequest.getBody();
      StringBuilder sb = new StringBuilder();
  
      body.subscribe(buffer -&gt; {
          byte[] bytes = new byte[buffer.readableByteCount()];
          buffer.read(bytes);
          DataBufferUtils.release(buffer);
          String bodyString = new String(bytes, StandardCharsets.UTF_8);
          sb.append(bodyString);
      });
      return sb.toString();
  
  }
  </code></pre>