ios - NSURLSession didReceiveChallenge 多个证书
<p><p>如何根据服务器指定多个证书?
在 <code>session:didReceiveChallenge</code> 方法中,我可以返回一个 NSURLCredential,但我没有找到一种方法来识别挑战来自哪个 URL。</p>
<p>我想做这样的事情:</p>
<pre><code>-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
// get the certificate depending on the url
NSString *certificatePath;
if () {
certificatePath = [[ bundlePath] stringByAppendingString:@"/server1.p12"];
} else if () {
certificatePath = [[ bundlePath] stringByAppendingString:@"/server2.p12"];
}
//... some certificate stuff
NSURLCredential *credential = ;
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>终于找到答案了,你可以像这样获取<code>NSURLAuthenticationChallenge</code>的宿主:</p>
<pre><code>NSString* host = challenge.protectionSpace.host;
</code></pre>
<p>就是这样</p></p>
<p style="font-size: 20px;">关于ios - NSURLSession didReceiveChallenge 多个证书,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40819385/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40819385/
</a>
</p>
页:
[1]