我正在用 Objective-C 开发一段代码,用于更快地执行 HTTP/HTTPS 请求。该代码将被插入到包含最常见执行操作的库中。我正在寻找一个服务器来测试需要身份验证的 HTTPS 请求。
特别是我看到 iOS 标准库有 NSURLConnection 类。 NSURLConnectionDelegate协议(protocol)有方法connection:didReceiveAuthenticationChallenge: 这就是我想在类里面测试的内容。
有什么吗?我在 Google 上进行了搜索,但一无所获。
最佳答案
是的,您是对的,您需要使用 NSURLConnectionDelegate 中的 didReceiveAuthenticationChallenge
这是一些示例用法
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
关于ios - 测试 HTTPS 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246288/