ios – 如何使用AFNetworking允许https连接?

前端之家收集整理的这篇文章主要介绍了ios – 如何使用AFNetworking允许https连接?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经设置了AFNetworking,但它不接受https网址.如何让AFNEtworking通过ssl进行连接.

我有以下代码

NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
                                path: pathstr
                          parameters: params
           constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
           {
               //TODO: attach file if needed
           }];



AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responSEObject) {
    //success!
    completionBlock(responSEObject);
} failure:^(AFHTTPRequestOperation *operation,NSError *error) {
    //failure :(

    NSLog(@"%@",error);
    completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];

[operation start];

解决方法

operation.securityPolicy.allowInvalidCertificates = YES;

这段代码非常重要.如果你不添加这个,你会收到一个错误.

原文链接:https://www.f2er.com/iOS/333386.html

猜你在找的iOS相关文章