[英]How do I accept a self-signed SSL certificate using iOS 7's NSURLSession and its family of delegate methods for development purposes?
[英]How to accept self-signed certificate with asihttprequest
我正在嘗試使用自簽名證書來處理我的應用程序。
我現在正在使用ASIHTTPRequest庫,如下所示:
- (IBAction)sendHttpsRequest
{
//Set request address
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"https://142.18.87.46:443"];
//call ASIHTTP delegates (Used to connect to database)
NSURL *url = [NSURL URLWithString:databaseURL];
//This sets up all other request
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setValidatesSecureCertificate:YES];
[request startAsynchronous];
}
我已經將setValidatesSecureCertificate設置為YES,希望會發生一些事情,但顯然什么都沒有,因為我不確定我必須做什么。
這是我在日志中收到的錯誤
2011-12-06 14:27:33.514 connectionTest[916:207] Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)" UserInfo=0x683a860 {NSUnderlyingError=0x68390d0 "The operation couldn’t be completed. (OSStatus error -9807.)", NSLocalizedDescription=A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)}
任何幫助將不勝感激。
我已經將setValidatesSecureCertificate設置為YES,希望會發生一些事情,但顯然什么都沒有,因為我不確定我必須做什么。
這就是問題。 它默認為YES
,您需要將其設置為NO
。 由於您的證書是自簽名的,因此iOS 無法驗證證書 - 系統中沒有簽署證書的受信任機構,因此沒有理由說它是有效的。 因此,如果您要求它驗證證書(這是默認值),則必須拒絕它。 您必須禁用證書驗證才能使自簽名證書生效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.