我收到了这个错误
The certificate for this server is invalid. You might be connecting to a server
that is pretending to be "server addres goes here" which could put your
confidential information at risk."
Run Code Online (Sandbox Code Playgroud)
我正在使用这种方法:
[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我试过这段代码:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
Run Code Online (Sandbox Code Playgroud)
但后来我在didReceiveResponse方法中获得了EXC_BAD_ACCESS.
使用NSURLRequest,我试图访问具有过期证书的网站.当我发送请求时,我的连接:didFailWithError委托方法被调用,具有以下信息:
-1203, NSURLErrorDomain, bad server certificate
Run Code Online (Sandbox Code Playgroud)
我的搜索只提出了一个解决方案:NSURLRequest中的隐藏类方法:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:myHost];
Run Code Online (Sandbox Code Playgroud)
但是,出于显而易见的原因,我不想在生产应用程序中使用私有API.
有关该怎么办的任何建议?我是否需要使用CFNetwork API,如果是,则需要两个问题:
编辑:
iPhone OS 3.0引入了支持这种方法.更多详细信息:如何使用NSURLConnection连接SSL以获取不受信任的证书?
Apple似乎已经删除了信任在iOS 10中自签名的SSL证书的功能.
我创建了自己的自签名证书,并拥有一个使用我的证书签名的本地Web服务器.我必须在iOS上安装我的证书才能在本地进行测试,因为我开发了一个需要信任我的证书的iOS应用程序.
如何安装自签名证书?