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

编程入门 行业动态 更新时间:2024-10-22 21:27:00
本文介绍了如何使用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忽略自签名证书

本文发布于:2023-11-02 14:49:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552687.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   证书   NSURLRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!