我想通過我的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