[英]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.