objective-c - 我想使用 AFNetworking 允许无效的 SSL 证书

标签 objective-c afnetworking

我想允许无效的 SSL 证书。 我的主要代码如下:

myClient = [[MyClient alloc] init];
[myClient getHtml:@"/path/to/the/distination.html"];

MyClient类代码如下:

#import <Foundation/Foundation.h>
#import "AFNetworking.h"

@interface MyClient : NSObject

- (void)getHtml:(NSString *)path;

@end

#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_

@implementation MyClient

- (void)getHtml:(NSString *)path
{
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://trusted.server.net"]];
    [httpClient getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error = %@", error);
    }];
}

@end

我阅读了下面的页面并尝试了宏,但这不起作用。

自签名证书 SSL · 问题 #189 · AFNetworking/AFNetworking https://github.com/AFNetworking/AFNetworking/issues/189

请帮帮我...

最佳答案

在 AFNetworking 2.0 中,您可以使用以下内容:

[AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES;

关于objective-c - 我想使用 AFNetworking 允许无效的 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12967220/

相关文章:

ios - 如何延迟/减慢 UIScrollView 平移速度

iphone - 将对象从 AppDelegate.m 传递到 View Controller

ios - 调频数据库队列错误 : database is locked

iphone - 如何让 AFHTTPRequestOperation 在完成时调用选择器,而不是 block ?

ios - 从服务器下载图像以显示在 CollectionView 上

objective-c - 使一系列按钮的响应都不同

ios - 在 MCSession 中设置最大对等点数

iphone - 无法从 Objective C 中的 block 代码更新 UIView

iphone - AFNetworking错误:“(200-299)中的预期状态代码,得到404”

iOS - 将字典作为参数从 AFNetworking GET 传递的问题