हां, AFNetworking सामान्य रूप से प्रमाणीकरण चुनौतियों के लिए ब्लॉक-आधारित प्रतिक्रिया प्रदान करके एनटीएलएम प्रमाणीकरण (या मूल रूप से कोई प्रमाणीकरण विधि) का समर्थन करता है।
यहां एक कोड उदाहरण है (operation
मानना AFHTTPRequestOperation
, AFJSONRequestOperation
आदि) है। ऑपरेशन शुरू करने से पहले प्रमाणीकरण चुनौती ब्लॉक इस तरह से सेट करें:
[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];
}
}];
सामान्य रूप से ऑपरेशन को प्रारंभ या एनक्यू करें और यह चाल चलाना चाहिए।
यह मूल रूप से विधि है वेन हार्टमैन describes in his blog AFNetworking पर लागू होता है।
स्रोत
2013-01-10 14:08:55
[AFNetworking NTLM प्रमाणीकरण?] के संभावित डुप्लिकेट? [Http://stackoverflow.com/questions/12483465/afnetworking-ntlm- प्रमाणीकरण) –