【发布时间】:2013-10-31 11:16:40
【问题描述】:
我在使用自签名证书建立与我的服务器的连接时遇到问题。在 RestKit 0.10.3 中,证书一切正常。
我这样初始化 RestKit:
AFHTTPClient * client = [AFHTTPClient clientWithBaseURL:baseURl];
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
client.defaultSSLPinningMode = AFSSLPinningModeCertificate;
client.allowsInvalidSSLCertificate = YES;
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
objectManager.managedObjectStore = managedObjectStore;
但 SSL-Certificate 被忽略 - 它不会被 AFNetworking 加载。
当我创建这样的请求时
NSMutableURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodGET path:[@"/myResource"] parameters:nil];
RKHTTPRequestOperation *httpRequestOperation = [[RKHTTPRequestOperation alloc] initWithRequest:request];
httpRequestOperation.SSLPinningMode = AFSSLPinningModeCertificate;
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithHTTPRequestOperation:httpRequestOperation
responseDescriptors:[RKObjectManager sharedManager].responseDescriptors];
证书已加载,但请求仍然失败,并显示以下消息:
2013-10-31 11:52:12.920 myApp[87552:651b] E restkit.network:RKObjectRequestOperation.m:576 对象请求失败: 基础 HTTP 请求操作失败并出现错误:错误 Domain=NSURLErrorDomain Code=-1012 "无法执行该操作 完全的。 (NSURLErrorDomain 错误 -1012。)“UserInfo=0x9470aa0 {NSErrorFailingURLKey=https://myDomain.com/myRessource NSErrorFailingURLStringKey=https://myDomain.com/myRessource} 2013-10-31 11:52:12.921 myApp[87552:651b] E restkit.network:RKObjectRequestOperation.m:238 GET 'https://myDomain.com/myRessource' (0 / 0 个对象) [请求=0.2065s 映射=0.0000s 总=0.2130s]:错误=错误域=NSURLErrorDomain Code=-1012 "操作无法完成。(NSURLErrorDomain 错误 -1012.)" 用户信息 = 0x9470aa0 {NSErrorFailingURLKey=https://myDomain.com/myRessource, NSErrorFailingURLStringKey=https://myDomain.com/myRessource} response.body=(null)
问题:
- 初始化 RestKit 的方法是否正确?我不想指定 每个请求中都有 SSL 内容。它应该是全局设置的。
- 知道请求失败的原因吗?
body=null看起来很可疑。
【问题讨论】:
-
嗨,我在 0.20.3 中也有相同的错误代码 1012,但是在我将 RestKit 更新到 0.22.0 后,它工作正常。
标签: ssl https restkit afnetworking restkit-0.20