您当前的位置: 首页 >  http

喜欢猪猪

暂无认证

  • 0浏览

    0关注

    228博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

OkHttpUtils 关于response.body().byteStream()的坑

喜欢猪猪 发布时间:2020-10-30 16:05:34 ,浏览量:0

起因: OkHttpUtils类使用遇到的一个坑记录,在使用流文件的时候,不能进行两次的response.body().byteStream(),否则第二次调用该方法的时候流是关闭的,不能进行使用了; /** * post请求,返回InputStream * * @param url * @param json * @return * @throws IOException */ public InputStream postInputStream(String url, String json) throws IOException {     RequestBody body = RequestBody.create(JSON, json);     Request request = new Request.Builder()             .url(url)             .post(body)             .build();     Response response = mOkHttpClient.newCall(request).execute();     if (response.isSuccessful()) {         return response.body().byteStream();     } else {         throw new IOException("Unexpected code " + response);     } }

/**
 * Returns a new {@code BufferedSource} that can read data 
关注
打赏
1648795721
查看更多评论
立即登录/注册

微信扫码登录

0.0379s