Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,757 Members 36,837 Now Online
XDA Developers Android and Mobile Development Forum

[Q] android open a password protected Website

Tip us?
 
coderms
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Aug 2014
Question [Q] android open a password protected Website

I used this code:

Code:
mWebViewVertreungsplan = (WebView)findViewById(R.id.webViewVertretung);
          mWebViewVertreungsplan.setVisibility(View.VISIBLE);
          mWebViewVertreungsplan.setWebViewClient(new WebViewClient());
          // Enable Javascript
          WebSettings webSettings = mWebViewVertreungsplan.getSettings();
          webSettings.setJavaScriptEnabled(true);
          mWebViewVertreungsplan.loadUrl("Username: Pasword @ domain. com");
On the on some devices it works, but on others it wont work. I geht the error 401 unauthorized.
 
Masrepus
Old
#2  
Masrepus's Avatar
Senior Member
Thanks Meter 73
Posts: 660
Join Date: Feb 2013
Default [Q] android open a password protected Website

Funny enough i am working on a project that has to do with a "substitution plan" as well (dunno what the correct english translation is) xD

You have to put the credentials inside the url header, and they have to be Base64 encoded

I use jsoup library to read the values from a pw protected site, so putting things into header is done differently, but same principle:

[...]Jsoup.connect("domain.com").header("Authorization" , "Basic " + encodedString).post()
encodedString is done like that:
String text ="unamewd";
byte[] data = null;
data = text.getBytes("UTF-8");
encodedString = Base64.encode(data, Base64.DEFAULT);

So only thing you would have to google is how to set url header for webview
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes