How to get response body in Zuul post filter?

前端 未结 6 1255
时光说笑
时光说笑 2021-01-04 06:55

How it is possible to read a response body while using Zuul as a proxy in post filter?

I am trying to call the code like this:

@Componen         


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-04 07:41

    Thanks for suggestion, this is the code I used that works.

    try (final InputStream responseDataStream = ctx.getResponseDataStream()) {
       final String responseData = CharStreams.toString(new InputStreamReader(responseDataStream, "UTF-8"));
       ctx.setResponseBody(responseData);
    } catch (IOException e) {
       logger.warn("Error reading body",e);
    }
    

提交回复
热议问题