在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 }];
时间: 2024-10-25 04:43:43