我正在开发一个登录模块。单击WebView中的“登录”按钮后,浏览器将收到json响应,然后重定向到另一个页面。我如何拦截这个json响应?
我尝试shouldOverrideUrlLoading (WebView view, String url)
并打印所有网址输入,但我找不到json响应。
mWebview.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
Log.i("InterceptRequest", url);
return super.shouldInterceptRequest(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i("onPageStarted", url);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("onPageFinished", url);
}
});
我还注意到,当我在Chrome和Firefox中看不到此响应时,我可以在IE中看到它。
谢谢。
答案 0 :(得分:1)
覆盖webclient上的shouldOverrideUrlLoading:
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
// read inputstream to get the json..
...
...
return true;
}