ios - 使用 SSL 证书将 iOS 应用程序与 Apache Server 连接?

标签 ios apache ssl afnetworking-2

我正在使用 AFNetworking 2.0,并且我在 Apache 服务器上启用了证书身份验证。 我在 xcode 项目中放置了一个 .crt 文件。 每当我尝试与服务器建立 https 连接时,我都会收到以下错误:

The operation couldn't be completed. (NSURLErrorDomain error -1012.)

这是调用服务器的代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]];
[manager POST:@"https://www.example.com/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //success
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //failure
}];

最佳答案

默认情况下,AFNetworking 仅针对 .cer 文件进行固定。

重命名您的证书,使其成为 .cer 而不是 .crt,它应该可以工作。

您可以通过查看固定的证书来查看它是否正常工作:

NSLog(@"Using %d pinned certificates", [manager.securityPolicy.pinnedCertificates count]);

关于ios - 使用 SSL 证书将 iOS 应用程序与 Apache Server 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20197180/

相关文章:

c++ - 寻找适用于 Windows 7 的 C++ 中的 poco ssl websocket 客户端示例

java - key 工具错误 : java. security.KeyStoreException: DER 未找到

ios - 尝试使用 reverseGeocodeLocation,但未执行 completionHandler 代码

ios - UITapGestureRecognizer 根本不工作

ios - 行编辑操作不起作用 Couchbase Lite iOS 1.3

apache - 在现有站点上使用 Tomcat 部署 Grails 应用程序

ios - 如何激活我的 iTunes Connect?

apache - 从 Apache 到 Nginx 的大括号({ 和 })重写规则。

apache - 连接已在 wamp 上重置

php - 无法使用 gmail 使用 php 发送电子邮件 - 授权错误