I need to add custom headers to EVERY request coming from the
WebView. I know
loadURL has the parameter for adding extra Headers, but those are only applied to only some of the requests.
All (resource related) requests do not contain the headers.
I have looked at all overrides in
WebViewClient, but nothing allows for adding headers to resource requests -
onLoadResource(WebView view, String url) and
shouldInterceptRequest(Webview,url). Any help would be wonderful.
shouldInterceptRequest(Webview,url) you can use the parameter
url to initial new http request by using
HttpPOST, here is example code :
DefaultHttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(<"your url for each request">); httpPost.setHeader("<header-name>", "<header-value>"); HttpReponse httpResponse = client.execute(httpPost); //here omit getting content-type and encoding InputStream reponseInputStream = httpReponse.getEntity().getContent();
Then you can put
return WebResourceResponse(<content-type>, <encoding>, reponseInputStream) in your
if you have any request which doesn't need add more header, just filter it and
shouldInterceptRequest(Webview,url) will do the rest.
Hope this can help.