测试HTTPS身份验证

时间:2013-03-06 11:34:31

标签: ios objective-c authentication https nsurlconnection

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

特别是我看到iOS标准库有类NSURLConnection。 NSURLConnectionDelegate协议具有方法连接:didReceiveAuthenticationChallenge: 这就是我想和我的班级一起测试的。

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

1 个答案:

答案 0 :(得分: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];
}