Reputation: 2224
Laoding external URL is having DialogBox with User Name and Password in to WebView. it gives me the error Authorization Required
URL "http://developer.xamarin.com:8081/api/todoitems"
I load many urls but not getting such error. But loading as above mention URL with Dialogbox for login it gives me error.
please help how I can display such url in WebView.
Upvotes: 0
Views: 1267
Reputation: 2207
You can Create Native WebView Renderer. Add a WebViewClient to this webview renderer:
webView.SetWebViewClient(new MyWebViewClient ());
Create MyWebViewClient
as follows with override OnReceivedHttpAuthRequest :
class MyWebViewClient : WebViewClient
{
public override void OnReceivedHttpAuthRequest(Android.Webkit.WebView view, HttpAuthHandler handler, string host, string realm)
{
Dialog dialog = new Dialog(view.Context);
dialog.SetContentView(/*Layout here*/);
dialog.Show();
//On submit Button Click from Layout set username and password:
handler.Proceed(userName, password);
}
}
The dialog is Layout in android project containing Username, password, submit and cancel fields. This you can create your own or take help from some pages.
Upvotes: 1
Reputation: 1513
You need to supply the credentials that are required for that page:
myWebview.SetHttpAuthUsernamePassword(host, realm, username, password);
Upvotes: 1