reza_khalafi
reza_khalafi

Reputation: 6554

Error Domain=NSURLErrorDomain Code=-1012 "(null)" in iOS Objective C

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

Answers (2)

dgatwood
dgatwood

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

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 2451

According to the docs:

NSURLErrorUserCancelledAuthentication = -1012

Here is the error list

More over HTTP status code 401 = Unauthorized

Upvotes: 2

Related Questions