I'm trying to access a URL from android WebView. While loading the URL i inspected through chrome that one header value is null (See the following image).
My question is, i want to update the Origin value. How can i do it?
Note: If Origin has null value only i've to update other wise i've to load as it is
For change request header you can use hashmap and add header key-value pairs
WebView web = findViewById(R.id.webView);
private Map<String, String> getHeaders() {
Map <String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Authorization", "Bearer");
return headers;
}
And next step need to create WebViewClient:
private WebViewClient getWebViewClient() {
return new WebViewClient() {
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString(), getHeaders());
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url, getHeaders());
return true;
}
};
}
Add WebViewClient to your WebView:
web.setWebViewClient(getWebViewClient());
webView = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
}
}
});
HashMap<String, String> headers=new HashMap<>();
webView.loadUrl("https://stackoverflow.com",headers);
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