多次通过okhttpclient从后端加载图片,导致socket is closed。有什么解决方吗码?保持长连接不行
public Bitmap getImageBitMap(String imgUrl) throws IOException { Bitmap bitmap; OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() .url(imgUrl) .build(); Response response = okHttpClient.newCall(request).execute(); byte[] bytes = Objects.requireNonNull(response.body()).bytes(); bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); return bitmap; }
后面发现和okhttpclient没关系。