我正在开发一个Android应用程序,用于过滤请求(使用白名单)并使用自定义SSLSocketFactory.为此,我开发了一个自定义WebViewClient,我已经覆盖了该shouldInterceptRequest方法.我可以过滤和使用我SocketFactory的GET请求,但我不能拦截POST请求.
那么,有没有办法拦截POST请求WebView?
这是shouldInterceptRequest方法的代码:
public final WebResourceResponse shouldInterceptRequest(WebView view, String urlStr) {
URI uri = URI.create(urlStr);
String scheme = uri.getScheme();
// If scheme not http(s), let the default webview manage it
if(!"http".equals(scheme) && !"https".equals(scheme)) {
return null;
}
URL url = uri.toURL();
if(doCancelRequest(url)) {
// Empty response
Log.d(TAG, "URL filtered: " + url);
return new WebResourceResponse("text/plain", "UTF-8", new EmptyInputStream());
} else {
Log.d(TAG, "URL: " + url);
HttpURLConnection conn = (HttpURLConnection) …Run Code Online (Sandbox Code Playgroud)