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);
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.
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.
webview.setWebViewClient(new WebViewClient() {
@SuppressLint("NewApi")
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
Log.d("", "request.getRequestHeaders()::"+request.getRequestHeaders());
return null;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With