如何从iOS上的非http url获取数据



我正在开发一个从网站获取RSS提要的应用程序,网址具有以下形式:

feed://feeds.<a_site_name>.org/...

由于它不是http协议,因此当我使用NSURLConnection和NSUrlRequest获取数据时,它总是返回零数据。

    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:feedURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];    
NSOperationQueue *aqueue = [[[NSOperationQueue alloc] init] autorelease];
[NSURLConnection sendAsynchronousRequest:request queue:aqueue completionHandler:^(NSURLResponse *response, NSData *resultJsonData, NSError *error)
         {
         }];

我已经使用ASIHttpRequest第三方库来获取,它可以工作,但我不想在这里使用第三方库。

我可以在iOS上使用任何给定的框架或任何简单的代码来获取吗?

feed:// URL

实际上只是一个HTTP或HTTPS URL,但旨在由知道如何处理RSS提要的应用程序读取。 解决此问题的方法是将URL方案更改为http(或https,如果可能的话(。 例如:

NSURLComponents *components = [NSURLComponents componentsWithURL:feedURL
                                         resolvingAgainstBaseURL:YES];
components.scheme = @"https";
feedURL = [components URL];

然后尝试该 URL,如果失败,请将方案更改为 http 并重试。

最新更新