我想允许无效的 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/