当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Password-protected web pages when accessed by Android

问题描述:

I have created a password protected static html page with a custom audio player, to be displayed in any browser and OSs. User/password access to the page works fine from any browser. But none of my attempts to make the player work for Android browsers worked. This is the link I have:

 <a title="play mp3 in new window" target="_blank" href="01.mp3"><img border="0" src="play.gif"></a>

If I remove the password, the player works in Android as well, so this would suggest an issue with playing media files on Android when the directory is password protected. The files are indeed in the same folder as the web page.

Thanks for any help,

Joe

网友答案:

You have to add your autorization to the webview headers:

Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Basic" + Base64.encodeToString(username + ':' + password),Base64.DEFAULT);

And then when you load your url add the headers as the second parameter.

webview.loadUrl("www.mysite.com",headers);

You can also use setHttpAuthUsernamePassword

分享给朋友:
您可能感兴趣的文章:
随机阅读: