zoukankan      html  css  js  c++  java
  • 安卓Response 获取body的正确方式

        public static String getResponseBody(Response response) {
    
            Charset UTF8 = Charset.forName("UTF-8");
            ResponseBody responseBody = response.body();
            BufferedSource source = responseBody.source();
            try {
                source.request(Long.MAX_VALUE); // Buffer the entire body.
            } catch (IOException e) {
                e.printStackTrace();
            }
            Buffer buffer = source.buffer();
    
            Charset charset = UTF8;
            MediaType contentType = responseBody.contentType();
            if (contentType != null) {
                try {
                    charset = contentType.charset(UTF8);
                } catch (UnsupportedCharsetException e) {
                    e.printStackTrace();
                }
            }
            return buffer.clone().readString(charset);
        }

    body.string()会截断流

  • 相关阅读:
    部署nginx服务
    mysql主从配置
    LNMP+WordPress博客搭建
    CIFS(Samba)服务的使用
    NFS服务的使用
    LVM逻辑卷
    FTP学习
    文件处理+生成器
    内置函数
    Python3
  • 原文地址:https://www.cnblogs.com/6324/p/7420037.html
Copyright © 2011-2022 走看看