gpt4 book ai didi

ios - Xamarin iOS : Pass credentials over http

转载 作者:行者123 更新时间:2023-11-29 00:20:16 26 4
gpt4 key购买 nike

我正尝试在我的 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 正在被调用,并且在循环中不断被调用。我没有得到预期的页面,而是得到一个空白页面,上面只写着“验证”

最佳答案

来自 Apple 的文档 PerformDefaultHandling :

Use the default handling for the challenge as though this delegate method were not implemented. The provided credential parameter is ignored.

请尝试使用 UseCredential:

var crendential = new NSUrlCredential("user", "pass", NSUrlCredentialPersistence.ForSession);

completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, crendential);

关于ios - Xamarin iOS : Pass credentials over http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44313063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com