Google 新闻 RSS 提要返回 didFailWithError -1002 代码

发布于 2024-11-26 07:07:30 字数 1182 浏览 0 评论 0原文

我正在以 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 技术交流群。

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

发布评论

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

评论(1

装纯掩盖桑 2024-12-03 07:07:30

将 feed:// 更改为 http:// 即可。

Change feed:// to http:// and it will work.

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