Android 拦截WebView请求,并加入或修改参数(GET)
生活随笔
收集整理的這篇文章主要介紹了
Android 拦截WebView请求,并加入或修改参数(GET)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
WebView提供了方法shouldInterceptRequest
?
mWebView.setWebViewClient(new WebViewClient() {@Nullable@Overridepublic WebResourceResponse shouldInterceptRequest(WebView view, String url) {if (url.contains("UserName")) {URL urlStr = null;try {urlStr = new URL(url+"?test=true");URLConnection rulConnection = urlStr.openConnection();HttpURLConnection conn = (HttpURLConnection) rulConnection;conn.setRequestProperty("Accept-Charset", "utf-8");conn.setRequestProperty("contentType", "utf-8");conn.setRequestMethod("GET");// Read inputString charset = conn.getContentEncoding() != null ? conn.getContentEncoding() : Charset.defaultCharset().displayName();String mime = conn.getContentType();InputStream isContents = conn.getInputStream();return new WebResourceResponse(mime, charset,isContents);} catch (Exception e) {e.printStackTrace();return null;}} else {return super.shouldInterceptRequest(view, url);}} });總結
以上是生活随笔為你收集整理的Android 拦截WebView请求,并加入或修改参数(GET)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 横竖屏切换时 Dial
- 下一篇: android sina oauth2.