起因:
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
