【问题标题】:Testing HTTPS authentication测试 HTTPS 身份验证
【发布时间】:2013-02-21 04:21:17
【问题描述】:
我正在用 Objective-C 开发一段代码,用于更快地执行 HTTP/HTTPS 请求。此代码将插入到包含最常见执行操作的库中。我正在寻找一个用于测试需要身份验证的 HTTPS 请求的服务器。
我特别看到 iOS 标准库有 NSURLConnection 类。 NSURLConnectionDelegate 协议有方法 connection:didReceiveAuthenticationChallenge:
这就是我想在课堂上测试的内容。
有什么事吗?我在 Google 上搜索过,但一无所获。
【问题讨论】:
标签:
ios
objective-c
authentication
https
nsurlconnection
【解决方案1】:
是的,你是对的,你需要使用来自 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];
}