ä»å¤©éå°ä¸ä¸ªéæ±ï¼H5å é¨è°ç¨ç»å½è¯·æ±ï¼ç¶åææºç«¯ç»ä»æ¼æ¥ç¨æ·çIDåå ¶ä»æ¶æ¯
è¿ä¸ªWebViewæä¾äºæ¹æ³shouldInterceptRequest
ä¸é¢ä»£ç ï¼åªæ¯ç®ådemoï¼è¯·æ±æ¹å¼æ¯get
mWebView.setWebViewClient(new WebViewClient() {
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.contains("UserName")) {
URL urlStr = null;
try {
urlStr = new URL(url+"?userId=12");
URLConnection rulConnection = urlStr.openConnection();
HttpURLConnection conn = (HttpURLConnection) rulConnection;
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setRequestMethod("GET");
// Read input
String 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);
}
}
});
Â