Ios 使用AF1.x进行SSL固定
我是AFNetworking框架和SSL固定的新手。 我已经做了以下工作:Ios 使用AF1.x进行SSL固定,ios,objective-c,ssl,ssl-certificate,afnetworking,Ios,Objective C,Ssl,Ssl Certificate,Afnetworking,我是AFNetworking框架和SSL固定的新手。 我已经做了以下工作: #define _AFNETWORKING_PIN_SSL_CERTIFICATES_ = 1 但你认为这还不够,对吗? 我该怎么做? 这是我目前的要求: NSArray *info = @{@"action" : @"test"}; NSError * error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:info opti
#define _AFNETWORKING_PIN_SSL_CERTIFICATES_ = 1
但你认为这还不够,对吗?
我该怎么做?
这是我目前的要求:
NSArray *info = @{@"action" : @"test"};
NSError * error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:info options:NSJSONWritingPrettyPrinted error:&error];
NSMutableURLRequest*request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:url]];
NSMutableData *body = [NSMutableData data];
[body appendData:jsonData];
[request setHTTPBody:body];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:request.URL];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation
*operation, id responseObject) {
NSError *error;
NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"response String %@",responseString);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@",error.localizedDescription); }];
[operation start];
请求工作正常,但我不知道它是否真的锁定了ssl。在调用start on
AFJSONRequestOperation
之前,您必须将SSLPiningMode
属性设置为AFSSLPiningModeCertificate
,才能使用哪个版本的AFNetworking?较旧版本使用了#define
,较新版本使用了AFHTTPClient
或operationAFNetworking 1上的属性,较旧版本使用了define。我想我让它工作了,但是我怎么能检查它的固定是否正确呢@大卫卡恩提亚……但具体是什么版本?1.您可以通过连接到https://httpbin.org/get
或类似,连接应失败并出现错误-1012我想我已成功连接,但未出现任何错误。谢谢你,大卫阿姨