RestKit 0.20.3使用证书进行不完整的初始化

时间:2013-10-31 11:16:41

标签: ssl https restkit afnetworking restkit-0.20

我在使用自签名证书建立与服务器的连接时遇到问题。在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对象)[request = 0.2065s   mapping = 0.0000s total = 0.2130s]:error = Error Domain = NSURLErrorDomain   代码= -1012“操作无法完成。(NSURLErrorDomain   错误-1012。)“UserInfo = 0x9470aa0   {NSErrorFailingURLKey = https://myDomain.com/myRessource,   NSErrorFailingURLStringKey = https://myDomain.com/myRessource}   response.body =(空)

问题:

  1. 初始化RestKit是否正确?我不想指定 每个请求都包含SSL内容。它应该设置为globaly。
  2. 知道请求失败的原因吗? body=null看起来很可疑。

1 个答案:

答案 0 :(得分:1)

在RKObjectManager中,您将找到:

#ifdef AFNETWORKING_PIN_SSL_CERTIFICATES
operation.SSLPinningMode = self.HTTPClient.defaultSSLPinningMode;
#endif

因此,如果直接使用对象管理器,则需要设置该定义。