¿AFNetworking admite authentication NTLM?
Sé que ASIHTTPRequest puede hacerlo, estoy intentando migrar a AFNetworking, pero tengo que asegurarme de que será capaz de manejarlo.
Realmente busqué en Internet para esto, pero no pude encontrar esta respuesta exacta.
Gracias a todos.
Sí, AFNetworking admite la authentication NTLM (o, básicamente, cualquier método de authentication) al proporcionar una respuesta basada en bloques a los desafíos de authentication en general.
Aquí hay un ejemplo de código (suponiendo que la operation
es AFHTTPRequestOperation
, AFJSONRequestOperation
, etc.). Antes de comenzar la operación, establezca el bloque de desafío de authentication así:
[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] useCnetworkingential:[NSURLCnetworkingential cnetworkingentialWithUser:@"username" password:@"password" persistence:NSURLCnetworkingentialPersistenceForSession] forAuthenticationChallenge:challenge]; } } else { // Authenticate in other ways than NTLM if desinetworking or cancel the auth like this: [[challenge sender] cancelAuthenticationChallenge:challenge]; } }];
Comience o encoja la operación como siempre y que debería hacer el truco.
Este es básicamente el método que Wayne Hartman describe en su blog aplicado a AFNetworking.