iphone - 如何使用 NSURLRequest 忽略自签名证书

标签 iphone ios nsurlrequest

我在尝试绕过/忽略自签名证书时需要帮助。我到处都看过,但到目前为止找不到任何对我有用的东西。

我正在尝试实现这个 here但是我不确定如何使用此代码

@implementation NSURLRequest(AllowAllCerts)

+ (BOOL) allowsAnyHTTPSCertificateForHost:(NSString *) host {
    return YES;
}

@end

我将它添加到我的应用委托(delegate)中,但我不知道如何处理它?<​​/p>

任何帮助将不胜感激..

目前我没有使用任何东西,因为没有任何东西对我有用..

最佳答案

这就是我让它工作的方式。 我在调用连接开始的方法下方添加了这两个方法。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

关于iphone - 如何使用 NSURLRequest 忽略自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9458989/

相关文章:

iphone - 将 mp3 从 Icecast 流式传输到 iPhone 应用程序

javascript - 使用 JavaScript/onorientationchange 在 iPhone 上重置 Safari 的比例/宽度/缩放

android - 如何在 React Native 中访问嵌套的 Text 元素中的链接?

iphone - 在不将其放在当前 UINavigationController 堆栈上的情况下创建新 View 的转场的正确方法是什么?

iphone - 核心数据 : any way to fetch multiple entities?

ios - OAuth 2 承载授权 header

iphone - 复杂的协议(protocol)和代表

ios - 如何在横向模式下调整 iOS 9 iPad 通知的今日扩展宽度?

ios - NSURL 始终为空

iphone - NSURLConnection 没有响应