iPhone - dataWithContentsOfURL: does not work for some URLs

给你一囗甜甜゛ 提交于 2019-12-12 01:31:33

问题


I am using NSData to get content from a URL (RSS feed) and then parse it. While most of the URLs are loaded fine, some of them don't return any data.

These URLs open on the web so I know they are valid, but they just don't return any NSData. One such URL - feed://jpl.nasa.gov/multimedia/rss/rovers.xml

Here's how I am using it (the NSURL object is formed properly)

NSURL *feedURL = [NSURL URLWithString:[myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *data = [NSData dataWithContentsOfURL:feedURL];

Any ideas why?

Thanks a lot.


回答1:


Switch to NSURLConnection so you have some delegate methods to watch what's happening in debugger. check out the URL Loading System docs if you haven't.



来源:https://stackoverflow.com/questions/1827364/iphone-datawithcontentsofurl-does-not-work-for-some-urls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!