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)》对你有帮助,请点赞、收藏,并留下你的观点哦!