【问题标题】:UIWebView: Error while loading URLUIWebView:加载 URL 时出错
【发布时间】:2010-12-04 10:11:54
【问题描述】:

我正在尝试为 Tom's Hardware 网站构建一个 RSS 阅读器。

当我尝试从 RSS 链接将 URL 加载到 UIWebview 时出现错误。

这是我的代码:

- (void)viewDidLoad {
 [super viewDidLoad];

 if (self.url != nil) {
  NSURL *requestUrl = [NSURL URLWithString:self.url];
  NSURLRequest *requestObj = [NSURLRequest requestWithURL:requestUrl];
  [webView loadRequest:requestObj];
 }
}

url由父控制器设置。

当 URL 直接来自 RSS 时,我在日志中有错误:

[2234:207] Error Domain=WebKitErrorDomain Code=101 UserInfo=0x3a6a240“操作无法完成。(WebKitErrorDomain 错误 101。)”

当我手动设置具有相同 URL 的 URL 时,它可以工作!

self.url = @"http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12";

这是一个 URL 示例:http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12。我不知道这个问题。

我希望你能帮助我。

最好的问候。

【问题讨论】:

  • 我们能否获得有关来自 RSS 的 URL 的更多信息?它采用什么格式?
  • 使用 NSLog() 检查 URL,然后将其复制并粘贴到 Safari 中,看看它是否加载。
  • 你是如何声明你的url属性的?
  • 失败的原因是NSURL将“#”转换为“%23”,所以你不能访问你指向的URL。

标签: iphone cocoa-touch uiwebview nsurl


【解决方案1】:

谢谢大佬,就是这样,我已经这样拆分了网址:

NSArray *split = [url componentsSeparatedByString:@"#"];

NSURL *requestUrl = [NSURL URLWithString:[[split objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

现在可以了,感谢您的帮助!

【讨论】:

    【解决方案2】:

    我有这段代码也触发了错误代码 101

     _request = [NSURLRequest requestWithURL:[NSURL URLWithString:redirectUrl]];
                [editorWebView loadRequest:_request];
    

    RedirectURL 是一个NSString,其格式为 http%3A%2F%2Fwww.linkedin.com%2Fnhome%2F

    我尝试使用NSString 的方法删除百分比转义,现在它可以工作了。

    [redirectUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    

    【讨论】:

      【解决方案3】:

      我认为问题可能是您的网址中的锚点,一位朋友也遇到了同样的问题

      【讨论】:

        猜你喜欢
        • 2015-10-14
        • 1970-01-01
        • 2011-01-28
        • 2011-02-10
        • 2013-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多