Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see request headers on Android WebView requests?

How can I intercept all requests made out of an Android WebView and get the corresponding request headers? I want to see the headers for every request made from my WebView including XHRs, script sources, css, etc.

The equivalent on iOS is to override NSURLCache which will give you all this information. The following are probably the closest to what I want but as far as I can see WebViewClient only ever gives us back strings:

void onLoadResource(WebView view, String url);
WebResourceResponse shouldInterceptRequest(WebView view, String url);
like image 477
Mike Kwan Avatar asked Oct 30 '13 19:10

Mike Kwan


People also ask

How do I send a post request in WebView?

webView. setWebViewClient(new WebViewClient(){ public void onPageStarted(WebView view, String url, Bitmap favicon) { super. onPageStarted(view, url, favicon); } public boolean shouldOverrideUrlLoading(WebView view, String url) { webView. postUrl(Base_Url, postData.

What is WebView in android studio?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.


1 Answers

webview.setWebViewClient(new WebViewClient() {
            @SuppressLint("NewApi")
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
                Log.d("", "request.getRequestHeaders()::"+request.getRequestHeaders());

                return null;
            }
        });
like image 170
Mayur More Avatar answered Sep 29 '22 23:09

Mayur More