如何使用asihttprequest接受自签名证书

如何使用asihttprequest接受自签名证书

本文介绍了如何使用asihttprequest接受自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自签名证书来处理我的应用程序。

I am trying to get a self-signed certificate to work with my application.

我现在正在使用ASIHTTPRequest库:

I am using the ASIHTTPRequest library at the moment like so :

- (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,希望会发生某些事情但很明显没有因为我不确定我该做什么。

I have set setValidatesSecureCertificate to YES in the hope that something would happen but obviously nothing has because I'm not sure what I have to do.

这是我在日志中收到的错误

This is the error I'm getting in my log

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)}

非常感谢任何帮助。

推荐答案

这就是问题所在。它默认为 YES ,您需要将其设置为。由于您的证书是自签名的,因此iOS 无法验证证书 - 系统中没有签署证书的受信任机构,因此没有理由说它是有效的。因此,如果您要求它验证证书(这是默认值),则必须拒绝它。您必须禁用证书验证才能使自签名证书生效。

This is the problem. It defaults to YES and you need to set it to NO. As your certificate is self-signed, iOS can't validate the certificate - there is no trusted authority in the system that has signed the certificate, so it has no basis for saying that it is valid. So if you ask it to validate the certificate (which is the default), it has to reject it. You have to disable certificate validation to get self-signed certificates to work.

这篇关于如何使用asihttprequest接受自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:58