ios - 测试 HTTPS 身份验证

标签 ios objective-c authentication https nsurlconnection

我正在用 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/

相关文章:

ios - 在 View 上自定义多个手势

ios - 如何从 NSDictionary 中的相应值获取键?

ios - 按距离对 UITableView 进行排序/排序

iphone - UITapGestureRecognizer 识别为 UILongPressGestureRecognizer

objective-c - iOS 应用程序和持久登录(显然是特定于手机和特定于应用程序的问题)

ios - 自动续订 App Store 订阅需要“恢复购买”吗?

ios - 范围超出范围大小 4 objective-c

android - 为什么 Corona SDK 的场景隐藏事件没有被触发?以及为什么即使我删除了场景,计时器仍在向控制台打印内容?

node.js - 在 Node.js Web 服务器中确定用户角色并授予 API 访问权限的正确方法是什么?

authentication - SSLPeerUnverifiedException 在尝试上传期间