2013-11-25 52 views
2

我正在使用AFNetworking 2.0,並且在Apache服務器上啓用了證書認證。 我已經在xcode項目中放置了一個.crt文件。 每當我嘗試建立HTTPS連接我碰到下面的錯誤服務器:使用SSL證書將iOS應用程序連接到Apache服務器?

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 
}]; 
+0

什麼樣的證書呢? – rdodev

+0

這是一個自簽名的SSL證書 – Carpsen90

+0

這是你的問題。 iOS對證書認證非常挑剔。您需要一個來自CA的完全合法的證書(您可以獲得一個免費試用版)。 – rdodev

回答

0

默認情況下AFNetworking只針對.cer文件銷。

重命名您的證書,使其爲.cer而不是.crt,它應該可以工作。

你可以看到,如果它的工作通過看固定證書:

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