Android WebView-如何在shouldInterceptRequest方法中获取post params?

时间:2017-10-01 04:11:20

标签: android cookies webview webviewclient ccavenue

我正在尝试拦截webview内部后续调用并使用请求标头传递Cookie。

我找到了一种方法,如下所示,

    @Override
                public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                    if (url.contains("/ccavenue_redirect_in") || url.contains("/ccavenue_cancel")) {
                        return loadRequestWithHeaders(url);
                    } else {
                        return super.shouldInterceptRequest(view, url);
                    }
                }

private WebResourceResponse loadRequestWithHeaders(String url) {
                try {
                    URL urlObject = new URL(url);
                    HttpURLConnection con = (HttpURLConnection) urlObject.openConnection();
                    con.setRequestMethod("POST");

                    CookieSyncManager.createInstance(PaymentWebviewActivity.this);
                    CookieManager cookieManager = CookieManager.getInstance();
                    cookieManager.removeSessionCookie();
                    cookieManager.setCookie(DOMAIN_NAME, AccountPreferenceUtils
                            .newInstance(PaymentWebviewActivity.this)
                            .getStringPrefs(AccountPreferenceUtils.PreferenceName.AUTH_COOKIE));
                    CookieSyncManager.getInstance().sync();

                    con.setRequestProperty("Cookie", AccountPreferenceUtils
                            .newInstance(PaymentWebviewActivity.this)
                            .getStringPrefs(AccountPreferenceUtils.PreferenceName.AUTH_COOKIE));

                    String[] types = parseContentHeader(con.getContentType());
                    return new WebResourceResponse(types[0], "UTF-8", con.getErrorStream());
                } catch (Exception ex) {
                    return null;
                }
            }

我可以传递cookie,但是在中断呼叫后,该网址有一些加密的主体。

了解如何修复它。

0 个答案:

没有答案