我正在尝试在UIWebView中加载windows身份验证的url。下面是我的代码。
public override void WillSendRequestForAuthenticationChallenge(NSUrlConnection connection, NSUrlAuthenticationChallenge challenge)
{
if (challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodNTLM)
{
if (challenge.PreviousFailureCount > 0)
{
challenge.Sender.CancelAuthenticationChallenge(challenge);
}
else
{
var credentialSpace = new NSUrlProtectionSpace("http://authenticatedurl.com", 80, "http", "http://authenticatedurl.com", "NTLM");
NSUrlCredentialStorage credentialStorage = NSUrlCredentialStorage.SharedCredentialStorage;
var credential = new NSUrlCredential ("username", "password", NSUrlCredentialPersistence.ForSession);
credentialStorage.SetDefaultCredential (credential, credentialSpace);
connection.UseCredential (credential, challenge);
connection.PerformDefaultHandling (challenge);
isAuthenticated = true;
}
}
}上面的委托被调用了,它成功地执行了UserCredential,没有任何错误,但网站没有加载。它不停地转了几个小时。我在这里做错了什么?
发布于 2017-03-08 18:50:26
var credentialSpace =新的NSUrlProtectionSpace("http://authenticatedurl.com",80,"http","http://authenticatedurl.com","NTLM");
尝尝这个,
var credentialSpace =新的NSUrlProtectionSpace("authenticatedurl.com",80,"http","authenticatedurl.com","NTLM");
它应该是有效的!
https://stackoverflow.com/questions/33185025
复制相似问题