UIWebView:加载 URL 时出错

发布于 2024-08-07 02:36:34 字数 973 浏览 5 评论 0原文

我正在尝试为 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。我不知道这个问题。

我希望你能帮助我。

此致。

I am trying to build an RSS reader for the Tom's Hardware website.

I have an error when I try to load an URL into an UIWebview from an RSS link.

Here'is my code:

- (void)viewDidLoad {
 [super viewDidLoad];

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

The url is setted by the parent controller.

When the URL comes directly from the RSS, I have an error in log:

[2234:207] Error Domain=WebKitErrorDomain Code=101 UserInfo=0x3a6a240 "Operation could not be completed. (WebKitErrorDomain error 101.)"

When I set manually the URL with the same URL like below, it work !

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

Here is an URL exemple: http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12. I have no idea about that problem.

I hope you can help me.

Best regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁轨上的流浪者 2024-08-14 02:36:34

谢谢大家,就是这样,我已经像这样分割了 URL:

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

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

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

Thanks guy, that'it, I have split the URL like this:

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

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

and now it work , thanks for your help !

痴者 2024-08-14 02:36:34

我有这个代码,它也会触发错误代码101

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

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

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

[redirectUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

I have this code which also triggers error code 101

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

RedirectURL is an NSString which has this format http%3A%2F%2Fwww.linkedin.com%2Fnhome%2F

I tried removing percent escapes using the method of NSString and it now works.

[redirectUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
猫腻 2024-08-14 02:36:34

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

I think the problem can be the anchor in your URL, a friend got the same problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文