Android如何拦截WebView之中的Post或者Get请求

来源:互联网 发布:腾讯云主机绑定域名 编辑:程序博客网 时间:2024/05/28 15:05
WebView webView = (WebView) findViewById(R.id.web_view);webView.setWebViewClient(new WebViewClient() {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {    Toast.makeText(getApplicationContext(), "WebViewClient.shouldOverrideUrlLoading",     Toast.LENGTH_SHORT);    view.loadUrl(url);    return true;}@Overridepublic void onPageStarted(WebView view, String url, Bitmap favicon) {Toast.makeText(getApplicationContext(), "WebViewClient.onPageStarted",     Toast.LENGTH_SHORT).show();// 这儿可以截获网页的URL,可以对URL进行分析。// 本例子之中是分析从通过RenRen登录成功后返回的access_token.if (url.contains("graph.renren.com/oauth/login_success.html")) {int start = url.indexOf("access_token") + "access_token=".length();int end = url.indexOf("expires_in") - 1;        accessToken = url.substring(start, end);    }super.onPageStarted(view, url, favicon);}});webView.loadUrl(myUrl);
0 0
原创粉丝点击