Download pictures, the size of the flow is 0
public static InputStream getLoadPicHttp(String url) throws IOException { Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); if (response.isSuccessful()) { Log.e("OkHttpUtils","isSuccessful"+response.body().toString()); return response.body().byteStream(); } else { Log.e("OkHttpUtils",response.body().string()); return new InputStream() { @Override public int read() throws IOException { return 0; } }; } } finallly InputStream is = (InputStream) msg.obj; Bitmap bitmap = BitmapFactory.decodeStream(is); mImageView.setImageBitmap(bitmap);
Is this way right?Why can't I get corrent InputStream?
From the Response doc, "Instances of this class are not immutable: the response body is a one-shot value that may be consumed only once. All other properties are immutable."
You can't call response.body().string() multiple times.
thank you!