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

标签 iphone ios 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)}

如有任何帮助,我们将不胜感激。

最佳答案

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.

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

关于iphone - 如何使用 asihttprequest 接受自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8394293/

相关文章:

iphone - if 语句的问题 ||

ios - 不能使用在 Swift 中使用的 Objective-C 中定义的 unwind segue

iPhone SDK : application icon not displaying in simulator

ios - 同时使用 Firebase 和 HockeyApp 时没有 HockeyApp 崩溃报告

iphone - ASIHttpRequest。关闭缓存

iphone - 频繁asihttprequest runrequests crash

iphone - 上传中断时最好的交互方式是什么?

iphone - 子类化的 UIView 没有设置标签

ios - 如何将闭包函数的返回值设置为变量?

iphone - 应用内购买免费订阅提示用户分享信息