gpt4 book ai didi

cocoa - 使用 NSURLConnection 忽略 SSL 证书错误

转载 作者:行者123 更新时间:2023-12-03 16:51:17 26 4
gpt4 key购买 nike

我正在使用 [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)] 从 Web 服务中提取数据,但Web服务器有自己颁发的证书,导致出现此错误:

SSL Error

使用时显示错误:

NSAlert *a = [NSAlert alertWithError:error];
[a runModal];

有什么办法可以忽略这个错误并继续吗?

最佳答案

按照链接问题中的说明,我为 NSURLConnection 定义了一个虚拟接口(interface):

@interface NSURLRequest (DummyInterface)
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end

并在创建请求之前调用该方法:

[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

这抑制了有关证书无效的错误。

关于cocoa - 使用 NSURLConnection 忽略 SSL 证书错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392043/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com