0

我正在用 Objective-C 开发一段代码来更快地执行 HTTP/HTTPS 请求。此代码将插入到包含最常见执行操作的库中。我正在寻找一个测试需要身份验证的 HTTPS 请求的服务器。

特别是我看到 iOS 标准库有 NSURLConnection 类。NSURLConnectionDelegate 协议有方法 connection:didReceiveAuthenticationChallenge: 这就是我想用我的班级测试的。

有什么事吗?我在谷歌上搜索,但一无所获。

4

1 回答 1

1

是的,你是对的,你需要didReceiveAuthenticationChallengeNSURLConnectionDelegate使用这里是一些示例用法

- (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];
}
于 2013-03-06T11:38:58.107 回答