I made two attempts to try to access an authenticated website, and I'm not sure what is wrong with my attempts. I have listed each of them. Has anyone tried this and got it to work?
This should not be difficult for Android Java programmers, and it doesnโt matter that I use monodroid EDIT (it matters because I have a Java implementation below that works fine) END EDIT.
I am trying to access the RDRS SSRS through WebView and I need to connect some common credentials.
ACTIVITY:
public static string username = "..."; public static string password = "..."; public static string website = "http://10.0.0.5/Reports"; private WebView webView; private void setupWebView(int attempt) { webView.Settings.JavaScriptEnabled = true; webView.Settings.BlockNetworkLoads = false; switch (attempt) { case 1: { webView.SetHttpAuthUsernamePassword(website, "", username, password); }break; case 2: { webView.SetWebViewClient(new AuthenticationClient(this)); }break; } webView.LoadUrl(website); } protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); webView = new WebView(this); setupWebView(1);
AuthenticationClient:
//DECLARED IN ANOTHER FILE [Android.Runtime.Register("android/webkit/WebViewClient", DoNotGenerateAcw = true)] public class AuthenticationClient:WebViewClient { private Context _context; public AuthenticationClient(Context context) { _context = context; } public override void OnReceivedError(WebView view, ClientError errorCode, string description, string failingUrl) { Toast.MakeText(_context, "OnReceivedError: " + errorCode, ToastLength.Long); //base.OnReceivedError(view, errorCode, description, failingUrl); } public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon) { Toast.MakeText(_context, "OnPageStarted: " + url, ToastLength.Long); //base.OnPageStarted(view, url, favicon); } public override bool ShouldOverrideUrlLoading(WebView view, string url) { Toast.MakeText(_context, "ShouldOverrideUrlLoading: " + url, ToastLength.Long); view.LoadUrl(url); return true; } public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) { Toast.MakeText(_context, "OnReceivedHttpAuthRequest: " + host, ToastLength.Long); handler.Proceed(Activity1.username, Activity1.password); } } //END DECLARATION
ATTEMPT 1: It doesn't even try to load the page. I keep getting the error message:
chrome (18710): external / chrome / net / http / http_auth_gssapi_posix.cc: 463: [0821/095922: ATTENTION: http_auth_gssapi_posix.cc (463)] Unable to find a compatible GSSAPI library
ATTEMPT 2: One message with a toast is not displayed.
I already looked:
http://developer.android.com/reference/android/webkit/WebView.html
Using WebView setHttpAuthUsernamePassword?
WebView.setHttpAuthUsernamePassword () not working?
Passing username and password for SSRS 2005 reports from a web application
OTHER STUFF
Now I have done it in Java and it works great. I still need a Mono solution for Android:
public class Android_reporttestActivity extends Activity { public static String username = "..."; public static String password = "..."; public static String website = "http://10.0.0.5/Reports"; private WebView setupWebView() { WebView webView = new WebView(this); webView.setWebViewClient( new WebViewClient(){ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { handler.proceed(username,password); } } ); return webView; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView webview = setupWebView();