Reputation: 6554
I requested to server with POST method, and server response me 401 status code. i have error 1012 and my response is nil.
//Send request
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Therefore i found some code for disable and change security mode in iOS Objective C request but is don't know how to use it and where set code. please help
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
[policy setValidatesDomainName:NO];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesCertificateChain:NO];
Upvotes: 0
Views: 4167
Reputation: 10417
First of all, do not disable certificate validation. It will not solve your problem. The server is rejecting the client's authentication, not the other way around.
Second, your problem is that the user's credentials are not in the keychain and you aren't providing delegate methods to provide credentials yourself. I'm not sure precisely how you do that with the AF API, but you can read about the way you would do it directly at https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html and use that as a starting point for understanding what is happening under the hood.
Upvotes: 0
Reputation: 2451
According to the docs:
NSURLErrorUserCancelledAuthentication = -1012
More over HTTP status code 401 = Unauthorized
Upvotes: 2