繁体   English   中英

ios-Restkit和SSL证书错误

[英]ios - Restkit and SSL certificate error

我有一台使用自签名SSL证书并运行Web服务的tomcat服务器。 我正在尝试使用Restkit连接到Web服务。 但是,我收到与证书有效性有关的错误。 这是我的代码:

NSURL *url=[NSURL URLWithString:baseURL];

RKClient *client = [RKClient clientWithBaseURL:url];
client.disableCertificateValidation=YES;

RKRequest *request = [client requestWithResourcePath:[NSString stringWithFormat:@"/addEvent?deviceID=%@&eventID=%@",deviceID,eventID]];
request.disableCertificateValidation=YES;
request.delegate=self;
RKResponse *response = [request sendSynchronously];

该请求失败,并出现以下错误:

2013-01-09 15:11:53.931 Mobile_ACPL[5761:907] The certificate for this server is invalid. You might be connecting to a server that is pretending to be “notify.acpl.lib.in.us” which could put your confidential information at risk.

即使将disableCertificateValidation设置为YES,我仍然收到此错误。 我该如何工作?

编辑:我试图添加证书,如下所示: https : //github.com/RestKit/RestKit/pull/131

我仍然得到相同的结果。

编辑2:看起来错误消息是在RKRequest.m中的此行上设置的:

    payload = [NSURLConnection sendSynchronousRequest:_URLRequest returningResponse:&URLResponse error:&error];

NSURLConnection不能满足同步调用中的身份验证挑战 您需要进行异步调用才能正常工作。

在我的情况下,我在RKClient上设置了disableCertificateValidation,但我使用的是使用不同RKClient的RKObjectManager。 在RKObjectManager初始化之后放置的以下行完成了该操作:

[RKObjectManager sharedManager].client.disableCertificateValidation = YES;

如果您使用RestKit使用

client.allowsInvalidSSLCertificate = YES;

将不起作用,而是这样做:

如果您将Rest Kit手动添加到项目中,请单击RestKit.xcodeproj转到项目> Build Settings> Preprocessor Macros

并添加_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1

多数民众赞成在完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM