验证iOS中的SSL证书
问题描述:
我创建了一个使用https托管的WCF Web服务,我需要使用iPhone应用程序访问此服务。
服务工作正常我可以使用浏览器检索数据。在这种情况下,我需要预先批准证书(“该服务器的证书无效”)
但是在iPhone应用程序中,我无法使其工作。
我迄今所做的是:验证iOS中的SSL证书
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
[[challenge sender]continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"%@",error.description); }
与错误的连接返回(说一个浏览器说什么)
的请求应该返回一个字符串或者很简单的东西。
我该怎么做呢?顺便说一句,我使用iOS5.0 感谢
答
发现了它,只需要一个多行添加到connection willSendRequestForAuthenticationChallenge
方法
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];