我知道如果使用以下 nsurlconnectiondelegate,问题将得到解决
- connection:willSendRequestForAuthenticationChallenge: - connection:canAuthenticateAgainstProtectionSpace
但是我正在尝试使用
sendAsynchronousRequest:queue:completionHandler:
所以你没有获取回调。我查阅了苹果文档,它说:
如果需要身份验证才能下载请求,则必须将所需的凭据作为 URL 的一部分指定。如果身份验证失败或缺少凭据,则连接将尝试在没有凭据的情况下继续。
我无法弄清楚如何做到这一点。当我搜索时,我只找到了这个私有调用
+(void)setAllowsAnyHTTPSCertificate:(BOOL)inAllow forHost:(NSString *)inHost;
有任何想法如何做到这一点吗?
以下是我收到的错误信息:
该服务器的证书无效。您可能正在连接到一个假冒“example.com”的服务器={NSErrorFailingURLStringKey=https://example.com/test/, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https://example.com/test/, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “example.com” which could put your confidential information at risk., NSUnderlyingError=0xa26c1c0 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “example.com” which could put your confidential information at risk.", NSURLErrorFailingURLPeerTrustErrorKey=
Allow Arbitrary Loads
设置为YES
的组合对我有效。 - Tanin