【问题标题】:HTTP load failed and I have tried all of the SO suggestions, but nothing worksHTTP 加载失败,我已经尝试了所有的 SO 建议,但没有任何效果
【发布时间】:2016-11-23 19:14:14
【问题描述】:

根据 Apple 的 docs,错误 9802 是“致命警报”。我查看了 Google 和 SO 并没有发现任何引用 9802 来解决此问题。我可以将我的代码更改为“apple.com”并获得该页面,但是使用我自己的 URL,我得到了上面的错误。我已经尝试了我能想到的一切,但没有任何效果。是时候寻求帮助了! :D

使用结果

/usr/bin/nscurl --ats-diagnostics https://pragerphoneapps.com

是否所有测试都失败了(结果上传here

这是我应用的 .plist 文件的图像(仅相关部分)

这是目标信息的图像:

这是我的代码:

- (IBAction)showHTMLHelp:(UIButton *)sender {

//  make the popover
UIViewController* popoverContent = [UIViewController new];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.preferredContentSize = CGSizeMake(450, 500);

NSString *urlAddress = @"https://pragerphoneapps.com";     // @"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL  *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//  add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame: popoverView.frame];
webView.backgroundColor = [UIColor whiteColor];  //  change background color here

//  add the webView to the popover
[webView loadRequest:requestObj];
[popoverView addSubview:webView];

//  if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
    [popoverController dismissPopoverAnimated:YES];
}

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

[popoverController presentPopoverFromRect:((UIButton *)oShowHelp).frame inView:self.view
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

【问题讨论】:

  • 它是否适用于 http 域?如果是这样,那么问题不太可能是您的代码。检查这个; stackoverflow.com/questions/38719075/…
  • no... 不适用于 http 或 https;给出此错误:App Transport Security 已阻止明文 HTTP (http://) 资源加载,因为它不安全。可以通过应用的 Info.plist 文件配置临时例外。
  • 您的目标站点已被入侵或证书不正确。它甚至不会在 chrome 中打开。
  • for https:,你说得对,它不是一个安全的网站,但我可以用 http: 打开它:并且只​​是 pragerphoneapps.com
  • 看来我需要该域的 SSL 证书(Apple 自 2017 年 1 月 1 日起的新要求);现在订购,应该会在 24 小时内安装并工作...安装后我会尽快回复您...谢谢约翰...稍后与您聊天

标签: objective-c uiwebview nsurlconnection ios10 nsurlrequest


【解决方案1】:

我强烈建议您修复您的 SSL 证书。 ATS 要求您拥有有效的 SSL 证书、TLS 1.2 或更高版本并支持前向保密。 这将是 2017 年初的要求,所以最好做好准备。

无论如何,同时尝试以下步骤以使其正常工作。

把它放在你的文件顶部:

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

在 Info.plist 中禁用应用传输安全。

在加载请求之前允许无效的 SSL 证书:

[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

成功加载您网站的示例代码:

NSString *urlAddress = @"https://pragerphoneapps.com";     // @"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
UIWebView *webView = [[UIWebView alloc] initWithFrame: self.view.frame];
webView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:webView];
[webView loadRequest:requestObj];

【讨论】:

  • 对不起,没用...得到这个:NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9802)
  • 获得 SSL 证书解决了这个问题;感谢您的提示!标清
【解决方案2】:

我想知道为什么它不能将“NSAllowArbitraryLoads 设置为 YES”。如果有缓存,请尝试重新启动您的 Mac 或 Xcode。 而且您的“例外域”设置格式错误。

【讨论】:

    猜你喜欢
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2014-06-16
    • 1970-01-01
    • 2012-12-15
    相关资源
    最近更新 更多