1

I need to fetch the records from my Web-Server through https protcol. My API calls has Basic Authentication. Now, am trying this with AFNetworking version 2.0x

After work around and find out simplest way to add Basic authentication here Now, i am getting problem with https call. When i execute my code,

NSDictionary *params = ....;

AFHTTPRequestOperationManager *manager = [SBAPIManager sharedManager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

@try {
    [manager POST:@"Create" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success - %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@", error);
    }];
} @catch (NSException *exception) {
    NSLog(@"Exception - %@", exception.description);
} 

Am getting below response only,

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7fd268560900 {NSErrorFailingURLKey=https://myapi.com/Create, NSErrorFailingURLStringKey=https://myapi.com/Create}

I found the github fixes issue But, AFNetworking 2.x has (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode; by default. How could i integrate this into my constraint.

Anyone has idea on this?

Community
  • 1
  • 1
Praveenkumar
  • 25,445
  • 23
  • 94
  • 171
  • it's looks like problem in your server. When I hit that server in browser or advanced rest client it's returning nothing. You can use below reusable code for service call https://github.com/SSamanta/SSRestClient – Susim Samanta Nov 12 '14 at 13:01
  • @San I have fixed. Thanks for your time – Praveenkumar Nov 13 '14 at 11:24

1 Answers1

2

Finally, found the answer by myself. The code below one fix my problem,

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:API_URL]];
manager.securityPolicy.allowInvalidCertificates = YES; // not recommended for production
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

For, self pinning with with AFNetworking we must include below one line to AFHTTPRequestOperationManager will provides the result,

manager.securityPolicy.allowInvalidCertificates = YES; // not recommended for production

Many thanks to

AFNetworking

Praveenkumar
  • 25,445
  • 23
  • 94
  • 171