Google 新闻 RSS 提要返回 didFailWithError -1002 代码
我正在以 RSS 源的形式下载 Google 新闻。如果我在浏览器中查看,一切正常。但是当我尝试使用以下代码下载为可读文件时,出现“-1002”错误。有什么想法吗?
- (void)viewDidLoad{
[super viewDidLoad];
path = @"feed://news.google.com/news?pz=1&jfkl=true&cf=all&ned=us&hl=en&q=oslo&cf=all&output=rss";
urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: path]];
urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
[urlConnection release];
}
#pragma mark Download RSS
// Start connection and download
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"didReceiveResponse");
rssData = [[NSMutableData data] retain];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)dataDownloaded {
NSLog(@"didReceiveData");
[rssData appendData:dataDownloaded];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSString * errorString = [NSString stringWithFormat:@"Error code %i", [error code]];
NSLog(@"error: %@", errorString);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
}
I am downloading Google news as an RSS feed. If I view in a browser, everything works fine. But when I try to download as a readable file using the following code I get a "-1002" error. Any ideas?
- (void)viewDidLoad{
[super viewDidLoad];
path = @"feed://news.google.com/news?pz=1&jfkl=true&cf=all&ned=us&hl=en&q=oslo&cf=all&output=rss";
urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: path]];
urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
[urlConnection release];
}
#pragma mark Download RSS
// Start connection and download
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"didReceiveResponse");
rssData = [[NSMutableData data] retain];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)dataDownloaded {
NSLog(@"didReceiveData");
[rssData appendData:dataDownloaded];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSString * errorString = [NSString stringWithFormat:@"Error code %i", [error code]];
NSLog(@"error: %@", errorString);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 feed:// 更改为 http:// 即可。
Change feed:// to http:// and it will work.