okhttp打印@body请求参数
非原创 javacoder 发表于:2023-04-02 19:33:38
  阅读 :289   收藏   编辑

在okhttp中打印@body里的请求参数方法

private static String bodyToString(final Request request){
    try {
      final Request copy = request.newBuilder().build();
      final Buffer buffer = new Buffer();
      if (Objects.isNull(copy) || Objects.isNull(copy.body())) {
        return "";
      }
      copy.body().writeTo(buffer);
      return buffer.readUtf8();
    } catch (final IOException e) {
      return "error";
    }
  }