Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用AF1.x进行SSL固定_Ios_Objective C_Ssl_Ssl Certificate_Afnetworking - Fatal编程技术网

Ios 使用AF1.x进行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

我是AFNetworking框架和SSL固定的新手。 我已经做了以下工作:

#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我想我已成功连接,但未出现任何错误。谢谢你,大卫阿姨