E / InputStreamUtil:在对从ShouldInterceptRequest返回的InputStream上调用available()时出现异常。这将导致 相关的失败请求。 java.io.IOException:已关闭 在okio.RealBufferedSource $ 1.available(RealBufferedSource.java:448) 在org.chromium.android_webview.InputStreamUtil.available(SourceFile:8)
当我尝试将OkHttp响应加载到Webview时出现此错误。 OkHttp响应inputstream包含
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fordconnect</title>
<base href="/common/login/">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="/common/login/runtime.xxxx.js">
</script>
<script type="text/javascript" src="/common/login/polyfills.yyy.js">
</script>
<script type="text/javascript" src="/common/login/styles.zzz.js">
</script>
<script type="text/javascript" src="/common/login/main.mmm.js"></script>
</body>
</html>
我们可以在Webview中使用javascript加载html吗? 我启用了JavaScript,并在清单文件中添加了INTERNET权限。
webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new Webviewclient());
webView.clearCache(false);
webView.clearHistory();
@NonNull
private WebResourceResponse getWebViewResponse(String url) {
Response response = null;
try {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new BasicAuthInterceptor("ddd",
"dadadada")).build();
final Call call = okHttpClient.newCall(new Request.Builder()
.url(url)
.get()
.build()
);
response = call.execute();
} catch (Exception e) {
e.printStackTrace();
}
return new WebResourceResponse("text/html", "utf-8", response.body().byteStream());
}
我在webview中得到的输出是网页不可用。