Post Reply

[Q] android open a password protected Website

31st August 2014, 12:50 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Aug 2014
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.
31st August 2014, 12:58 PM   |  #2  
Masrepus's Avatar
Senior Member
Thanks Meter: 74
 
662 posts
Join Date:Joined: Feb 2013
More
[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
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank