如何使用NSURLRequest忽略自签名证书 [英] how to ignore self-signing certificate with NSURLRequest

查看:54
本文介绍了如何使用NSURLRequest忽略自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need help with trying to bypass/ignor a self signing certificate.. I have looked everywhere and cannot find anything that has worked for me thus far..

我正在尝试实施

I am trying to implements this here however im not sure how to use this code

@implementation NSURLRequest(AllowAllCerts)

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

@end

我将其添加到我的应用程序委托中,但是然后我不知道该怎么办?

I add it to my app delegate but then I dont know what to do with it?

任何帮助将不胜感激..

any help would be greatly appreciated..

当前我什么也没用,因为没有任何效果对我有用.

currently I am not using anything because nothing has worked for me..

推荐答案

这就是我的工作方式.我在调用连接的方法的下面添加了这两个方法.

This is how I got it to work. I added these two methods just below the method where I call my connection to start.

- (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];
}

这篇关于如何使用NSURLRequest忽略自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆