我在使用自签名证书建立与我的服务器的连接时遇到问题。在 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 请求操作失败并出现错误:错误域 = NSURLErrorDomain 代码 = -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 个对象) [request=0.2065s mapping=0.0000s total=0.2130s]: error=Error Domain=NSURLErrorDomain Code=-1012 "操作无法完成。(NSURLErrorDomain error -1012.)" UserInfo =0x9470aa0 {NSErrorFailingURLKey= https://myDomain.com/myRessource , NSErrorFailingURLStringKey= https://myDomain.com/myRessource } response.body=(null)
问题:
- 这是初始化RestKit的正确方法吗?我不想在每个请求中都指定 SSL 内容。它应该是全局设置的。
- 知道为什么请求失败吗?
body=null
看起来很可疑。