我想通过我的xamarin iOS项目上的http传递凭据,但它不工作。Xamarin iOS:通过http传递凭证
public partial class WebView : UIViewController
{
protected override void ViewDidLoad()
{
webView.LoadRequest(new NSUrlRequest(new NSUrl("https:example.com")));
webView.AllowsBackForwardNavigationGestures = true;
webView.NavigationDelegate = new WebViewDelegate(this);
}
}
public class WebViewDelegate : WKNavigationDelegate, INSUrlConnectionDataDelegate
{
public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler)
{
//base.DidReceiveAuthenticationChallenge(webView, challenge, completionHandler);
completionHandler(NSUrlSessionAuthChallengeDisposition.PerformDefaultHandling, new NSUrlCredential("username", "password", NSUrlCredentialPersistence.ForSession));
Console.WriteLine("We are authenticated");
return;
}
}
任何人都可以建议如何解决这个问题?
更新:
DidReceiveAuthenticationChallenge被调用,并正在以不断循环调用。不但得不到预期的页面,我得到一个空白页面,它只是说,“验证”
请界定 “不工作”。它会崩溃吗?它是否给出错误?它是否加载任何东西? DidReceiveAuthenticationChallenge是否被调用? – Jason
更新了我的问题 – TheDeveloper