【发布时间】:2014-01-17 14:14:20
【问题描述】:
我是 AFNetworking 框架和 SSL Pinning 的新手。 我已经做了:
#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。
【问题讨论】:
-
您使用的是哪个版本的 AFNetworking?旧版本使用
#define,新版本使用AFHTTPClient或操作上的属性 -
AFNetworking 1,较旧的定义。我想我让它工作了,但我如何检查它是否正确固定? @DavidCaunt
-
是的...但是具体是什么版本? 1.?您可以通过连接到
https://httpbin.org/get或类似名称来检查它是否正常工作,连接应该失败并出现错误 -1012 -
我想我成功了,没有收到任何错误。谢谢@DavidCaunt
标签: ios objective-c ssl ssl-certificate afnetworking