Adding custom headers on all browsers

我怕爱的太早我们不能终老 提交于 2020-08-27 19:31:17

问题


I am working on a application where i want to add headers to browser in android. Its working pretty fine on Google chrome.

But this is not working on other available browsers like Firefox, UC browser, OperaMini, Dolphin

Below is the code that i tried.

Intent mIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(URL));
Bundle bundle = new Bundle();
bundle.putString(Constants.REQUEST_HEADER_TOKEN, "token");
bundle.putString(Constants.REQUEST_HEADER_AUTH, "Basic bfjdslfs");
mIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(mIntent);

Any help will be appreciated.Thanks in advance.


回答1:


There is no requirement that browsers pay any attention to extras like EXTRA_HEADERS, REQUEST_HEADER_TOKEN, etc.

Either use WebView or live without the headers always being added.




回答2:


This solution definitely works with mobile chrome browser ( haven't test ob others)

 Intent mIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(URL));
    Bundle bundle = new Bundle();
    bundle.putString("Authorization", "Basic " + token);
    mIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
    startActivity(mIntent);

However be careful with links for files that can be opened in some other default application.

In my case, there was problem with pdf Every link that ends with .pdf (http://lol.com/test.pdf) is opening not in web browser but in some pdf reader and then EXTRA_HEADERS aren't sent.



来源:https://stackoverflow.com/questions/38438069/adding-custom-headers-on-all-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!