首页 > 代码库 > AFNetworking2.0 访问HTTPS服务器

AFNetworking2.0 访问HTTPS服务器

在AFNetworking2.0下想要访问HTTPS服务器,需要做如下设置:

 

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];    [securityPolicy setAllowInvalidCertificates:YES];        NSURL *URL = [NSURL URLWithString:url];    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];    AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];    [op setSecurityPolicy:securityPolicy];    op.responseSerializer = [AFJSONResponseSerializer serializer];    [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {        //Success    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {        //Failed    }];

 

AFNetworking2.0 访问HTTPS服务器