android webview post 劫持,android – 在WebView中拦截POST请求

我正在开发一个Android应用程序过滤请求(使用白名单)和使用自定义SSLSocketFactory。为此,我开发了一个自定义的WebViewClient,我已经覆盖了shouldInterceptRequest方法。我可以过滤和使用我的SocketFactory与GET请求,但我不能拦截POST请求。

那么,有没有办法拦截WebView中的POST请求?

这里是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) url.openConnection();

conn.setRequestProperty("User-Agent", mSettings.getUserAgentString());

// Configure connections

configureConnection(conn);

String mimeType = conn.getContentType();

String encoding = conn.getContentEncoding();

if(mimeType != null && mimeType.contains(CONTENT_TYPE_SPLIT)) {

String[] split = mimeType.split(CONTENT_TYPE_SPLIT);

mimeType = split[0];

Matcher matcher = CONTENT_TYPE_PATTERN.matcher(split[1]);

if(matcher.find()) {

encoding = matcher.group(1);

}

}

InputStream is = conn.getInputStream();

return new WebResourceResponse(mimeType, encoding, is);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值