【发布时间】:2013-08-16 17:50:08
【问题描述】:
我正在尝试使用ShouldInterceptRequest 拦截 webview 请求,在其中我使用 HttpUrlConnection 从服务器获取数据,我将其设置为遵循重定向,这对 webviewclient 是透明的。这意味着当我返回 WebResponseResource("", "", data_inputstream) 时,webview 可能不知道目标主机已更改。我怎样才能告诉 webview 这发生了?
ourBrowser.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view,
String url) {
..... //some code omitted here
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) newUrl.openConnection();
conn.setFollowRedirects(true);
} catch (IOException e) {
e.printStackTrace();
}
..... //
InputStream is = null;
try {
is = conn.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return new WebResourceResponse(mimeType, encoding, is);
}
}
如果我请求“google.com”,它应该被重定向到“google.co.uk”,但webview不知道重定向,如果附加“co.uk”的css文件的链接是“/render/ something.css",webview 仍然去 "http://www.google.com/render/something.css" 找到应该是 "http://www.google.co.uk/render/something.css" 的 css 文件。
谁能帮帮我?
【问题讨论】:
标签: android redirect webview webviewclient android-webview