gpt4 book ai didi

ios - AFNetworking 是否支持 NTLM 身份验证?

转载 作者:可可西里 更新时间:2023-11-01 04:36:04 24 4
gpt4 key购买 nike

AFNetworking 是否支持 NTLM 身份验证?

我知道 ASIHTTPRequest 可以做到,我正在尝试迁移到 AFNetworking,但我必须确保它能够处理它。

我真的在网上搜索过这个,但我找不到这个确切的答案。

谢谢大家

最佳答案

是的,AFNetworking 通过提供对一般身份验证挑战的基于 block 的响应来支持 NTLM 身份验证(或基本上任何身份验证方法)。

这是一个代码示例(假设 operation 是一个 AFHTTPRequestOperationAFJSONRequestOperation 等)。在开始操作之前,像这样设置身份验证质询 block :

[operation setAuthenticationChallengeBlock:
^( NSURLConnection* connection, NSURLAuthenticationChallenge* challenge )
{
if( [[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodNTLM )
{
if( [challenge previousFailureCount] > 0 )
{
// Avoid too many failed authentication attempts which could lock out the user
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
else
{
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"username" password:@"password" persistence:NSURLCredentialPersistenceForSession] forAuthenticationChallenge:challenge];
}
}
else
{
// Authenticate in other ways than NTLM if desired or cancel the auth like this:
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}];

像往常一样启动或排队操作,这应该可以解决问题。

这基本上就是 Wayne Hartman 的方法 describes in his blog适用于 AFNetworking。

关于ios - AFNetworking 是否支持 NTLM 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13548448/

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