我已经设置了AFNetworking,但是它不接受https网址。我如何才能通过SSL进行AFNEtworking连接。

我有以下代码:

  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;
此代码非常重要。如果不添加,则会出现错误。

关于ios - 如何使用 AFNetworking 允许 https 连接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14900572/

10-11 15:13