如何使用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 无法validation证书 – 系统中没有签署证书的受信任机构,因此没有理由说它是有效的。 因此,如果您要求它validation证书(这是默认值),则必须拒绝它。 您必须禁用证书validation才能使自签名证书生效。