FORUMS

[Q] android open a password protected Website

1 posts
Thanks Meter: 0
 
By coderms, Junior Member on 31st August 2014, 12:50 PM
Post Reply Subscribe to Thread Email Thread
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: 93
 
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
Display Modes