Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
AFSSL证书失败iOS_Ios_Ssl_Ssl Certificate_Afnetworking 2 - Fatal编程技术网

AFSSL证书失败iOS

AFSSL证书失败iOS,ios,ssl,ssl-certificate,afnetworking-2,Ios,Ssl,Ssl Certificate,Afnetworking 2,我花了很多时间寻找答案,但还是没有运气,所以我决定放弃,寻求社区帮助: 1我有一个具有自签名证书的开发服务器 2是的,我使用了policy.allowInvalidCertificates=Yes 3 SSL位于自定义端口44302上 4我需要运行下载任务,因为请求返回数据流 这是我的密码: NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFU

我花了很多时间寻找答案,但还是没有运气,所以我决定放弃,寻求社区帮助:

1我有一个具有自签名证书的开发服务器

2是的,我使用了
policy.allowInvalidCertificates=Yes

3 SSL位于自定义端口44302上

4我需要运行下载任务,因为请求返回数据流

这是我的密码:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
policy.allowInvalidCertificates = YES;
manager.securityPolicy = policy;

NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://self_signed_cert.net:44302/storage/%@/action.download", _ticketId]];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    } else {
        NSLog(@"%@ %@", response, responseObject);
    }
}];
[dataTask resume];
以下是错误:

2015-08-03 18:18:15.901 SSL_测试[1517:23943]错误:错误 Domain=nsurErrorDomain Code=-1200“发生SSL错误,并且 无法与服务器建立安全连接。“UserInfo=0x787d2f20 {NSLocalizedDescription=发生了SSL错误,并且发生了安全错误 无法连接到服务器。, nsLocalizedRecoverysSuggestion=是否要连接到服务器 无论如何?,kCFStreamErrorCodeKey=-9806, NSErrorFailingURLStringKey=, _kCFStreamErrorDomainKey=3,NSUnderlyingError=0x787da700“操作无法完成。(kCFErrorDomainCFNetwork错误 -1200.),NSErrorFailingURLKey=}


非常感谢您的帮助!谢谢。

我尝试了一个空项目,它在应用程序上工作:

NSURL* lBaseURL = [NSURL URLWithString:@"https://myDomain/"];
    AFHTTPSessionManager* lSessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:lBaseURL
                                              sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];


    AFSecurityPolicy* lPolicy= [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    lPolicy.allowInvalidCertificates = YES;

    lSessionManager.securityPolicy = lPolicy;


    [lSessionManager GET:@"https://myDomain/api/"
              parameters:nil
                 success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull JSON)
     {
         NSLog(@"success %@", JSON);
     }
                 failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error)
     {
         NSLog(@"failure %@", error);
     }];
  • 别忘了将你的.cer文件添加到你的目标(在应用程序和watch应用程序中)
  • 将ATS激活到.plist
    NSAppTransportSecurity
但我一直在使用watchOS 2.0扩展。它只是因为以下错误而失败:

Error Domain=NSURLErrorDomain Code=-1200“发生SSL错误 无法与服务器建立安全连接。” UserInfo={nsLocalizedRecoverysSuggestion=是否要连接到 服务器是否仍然存在?,NSErrorFailingURLKey=, _kCFStreamErrorCodeKey=-9802,NSErrorFailingURLStringKey=,, NSErrorClientCertificateStateKey=0,kCFStreamErrorDomainKey=3, NSLocalizedDescription=发生SSL错误,并且发生了安全错误 无法连接到服务器。}


你解决问题了吗?我也经历过同样的情况…我们将上载和下载移动到http,它仍然不起作用,sryMaybe您是否也应该将.cer文件添加到您的扩展名?我忘了提到我添加了。