okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Download pictures, the size of the flow is 0

Open XiaNaLee opened this issue 11 years ago • 2 comments

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?

XiaNaLee avatar Apr 14 '15 15:04 XiaNaLee

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.

swankjesse avatar Apr 15 '15 03:04 swankjesse

thank you!

XiaNaLee avatar Apr 15 '15 08:04 XiaNaLee