Sì, AFNetworking supporta l'autenticazione NTLM (o praticamente qualsiasi metodo di autenticazione) fornendo una risposta basata su blocchi alle sfide di autenticazione in generale.
Ecco un esempio di codice (supponendo che operation
sia un AFHTTPRequestOperation
, AFJSONRequestOperation
ecc.). Prima di avviare l'operazione di impostare il blocco di richiesta di autenticazione in questo modo:
[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];
}
}];
Start o Enqueue l'operazione come al solito e che dovrebbe fare il trucco.
Questo è in pratica il metodo Wayne Hartman describes in his blog applicato a AFNetworking.
fonte
2013-01-10 14:08:55
possibile duplicazione di [AFNetworking NTLM Authentication?] (Http://stackoverflow.com/questions/12483465/afnetworking-ntlm-authentication) –