I was trying intercept webview request using: ShouldInterceptRequest
, inside it I used HttpUrlConnection
to fetch data from server, I set it to follow the redirection, which is transparent to webviewclient. This means when I return WebResponseResource("", "", data_inputstream), webview maynot know the target host was changed. How can I tell the webview this happened?
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);
}
}
If I request "google.com", it should be redirected to "google.co.uk", but webview didnt know the redirection, if the link of css file attaching with "co.uk" is "/render/something.css", the webview still go to "http://www.google.com/render/something.css" to find the css file which should be "http://www.google.co.uk/render/something.css".
Anyone can help me?