繁体   English   中英

https请求如何使用NSURLConnection处理

[英]How https request is handling using NSURLConnection

有人可以帮我知道如何使用NSRULConnection处理https请求吗? 我经历了很多教程和Apple文档。 但是我无法理解它是如何工作的。 我已经实现了以下委托来处理https请求。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
{    
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{       
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}

当实现上述委托时,我成功地从服务器获得了响应。 谁能帮我知道这是如何工作的。 另外,委托中的每个参数是什么,它在做什么?

提前致谢。

protectionSpace视为服务器。 委托方法connection: canAuthenticateAgainstProtectionSpace用于询问您是否可以处理服务器的身份验证要求。 在您的情况下,您说“如果我们正在谈论SSL证书(这就是NSURLAuthenticationMethodServerTrust通常意思),是的,我可以处理”。

该连接,然后要求你做到一点connection:didReceiveAuthenticationChallenge并提供NSURLCredential这个特定的服务器。 使用credentialForTrust:通过使用存储在此服务器证书的钥匙串中的信息来创建证书。 使用useCredential:forAuthenticationChallenge:最后,您使用此凭据告诉连接来回答挑战,即使用钥匙串数据来验证证书。

暂无
暂无

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

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