Back

android - okhttp3 与 本地缓存需要注意的点

发布时间: 2017-08-13 10:49:00

要使用 okhttp 自带的 stream 来返回给 webViewResponse .

不能使用 java string to input 那个stackoverflow 高票答案的方法.

return new WebResourceResponse(getMimeTypeBySuffix(url), "utf-8", response.body().byteStream());
// 不能这样:
//         new WebResourceResponse(getMimeTypeBySuffix(url), "utf-8", new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));

Back