NSURLConnection失败,错误代码为-1001

NSURLConnection失败,错误代码为-1001

问题描述:

我们正试图为我们的大学制作iPad报纸应用程序。我们的尝试是使用NSXMLParser从报纸网站直接解析。我们成功地解析了头条新闻。我的意思是我们可以解析文章的标题,摘要,链接和pubDate。下一步是解析每篇文章的主体,以便我们可以从每篇文章中检索几个句子以进行布局。因此,我们决定创建两个解析器类:一个用于解析标题,另一个用于解析每个链接中的文章。正如我前面提到的,我们可以成功地解析标题,但是在我们的其他解析器类(InnerParser.m)中,NSURLConnection失败,错误代码为-1001,这意味着超时。这里是报刊文字网站NSURLConnection失败,错误代码为-1001

http://theaggie.org/rss/headlines.xml

当我们尝试另一个网站时,出现错误代码-1000,它意味着坏链接的URL。下面是URL

​​

我知道肯定有什么问题在我们的代码,但我们无法弄清楚。这是我在stackoverflow上的第一篇文章。我不知道我应该发布多少代码。我将包含来自控制台的一些代码和日志。如果这些还不够,我愿意将我们的整个代码展示给那些可以慷慨地与我们分享知识的人。任何帮助将不胜感激。谢谢大家。

这里是我们得到错误

- (void)parseRssFeed:(NSString *)url withDelegate:(id)aDelegate { 
[self setDelegate:aDelegate]; 

NSLog(@"*****************************************************************************************"); 
NSLog(@"Inner parser link:%@", url); 
NSLog(@"*****************************************************************************************"); 

storyData = [[NSMutableData data] retain]; 

NSURL *baseURL = [[NSURL URLWithString:url] retain]; 

NSLog(@"Step 1: What about Here!"); 

NSURLRequest *request = [NSURLRequest requestWithURL:baseURL]; 

NSLog(@"Step 2: What about Here!"); 

[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 

NSLog(@"Step 3: What about Here!"); 

} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
NSLog(@"Did Recieve Response!?"); 
[storyData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
NSLog(@"Did Recieve Data!?"); 
[storyData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
NSString * errorString = [NSString stringWithFormat:@"Unable to download xml data (Error code %i)", [error code]]; 

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[errorAlert show]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 

NSLog(@"Did Finish Loading!?"); 

self.news = [[Story alloc] init]; 

NSXMLParser *storyParser = [[NSXMLParser alloc] initWithData:storyData];//story source code now contained in storyData 

[storyParser setDelegate:self]; // May need to change the name of rssParser to something else 

[storyParser parse]; 

} 

代码这里是从控制台某些日志

2011-04-08 20:34:51.936 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.938 TheCalAggie[794:207] Adding story title: Aggie Daily Calendar 
2011-04-08 20:34:51.938 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/07/aggie-daily-calendar 
2011-04-08 20:34:51.939 TheCalAggie[794:207] Summary: TODAY: Challah For Hunger; Shinkoskey Noon Concert: Zoila Muñoz; Student Services and Fees Administrative Advisory Committee 
2011-04-08 20:34:51.940 TheCalAggie[794:207] Published on: Thu, 07 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.941 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.942 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.942 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.943 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.944 TheCalAggie[794:207] Adding story title: Becoming an undergraduate researcher 
2011-04-08 20:34:51.945 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/07/becoming-an-undergraduate-researcher 
2011-04-08 20:34:51.946 TheCalAggie[794:207] Summary: Researching as an undergraduate can provide opportunities for those pursuing post-graduate study and experience working in a specific field. 
2011-04-08 20:34:51.946 TheCalAggie[794:207] Published on: Thu, 07 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.947 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.948 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.949 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.950 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.951 TheCalAggie[794:207] Adding story title: Aggie Daily Calendar 
2011-04-08 20:34:51.952 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/06/aggie-daily-calendar 
2011-04-08 20:34:51.953 TheCalAggie[794:207] Summary: Veggie Bed Prep Workshop; French Club Meeting; Third Street Improvements Final Community Workshop; Delta Epsilon Mu Games Night; The Spokes Auditions; Bistro 33 Poetry Night Reading Series. 
2011-04-08 20:34:51.954 TheCalAggie[794:207] Published on: Wed, 06 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.955 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.956 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.957 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.957 TheCalAggie[794:207] We recieved the article! 
2011-04-08 20:34:51.958 TheCalAggie[794:207] Article: *nil description* 
2011-04-08 20:34:51.959 TheCalAggie[794:207] What is in sections: (
(null) 
) 
2011-04-08 20:34:51.963 TheCalAggie[794:207] ***************************************************************************************** 
2011-04-08 20:34:51.965 TheCalAggie[794:207] Inner parser link:http://theaggie.org/article/2011/04/07/federal-government-cites-uc-davis-for-animal-cruelty 
2011-04-08 20:34:51.966 TheCalAggie[794:207] ***************************************************************************************** 
2011-04-08 20:34:51.966 TheCalAggie[794:207] Step 1: What about Here! 
2011-04-08 20:34:51.967 TheCalAggie[794:207] Step 2: What about Here! 
2011-04-08 20:34:51.968 TheCalAggie[794:207] Step 3: What about Here! 
2011-04-08 20:34:51.976 TheCalAggie[794:207] Parsing is done Parser class! 

是变量url正确定义?如果我正确地读取了你的代码,你应该是NSLog(),你的url变量,你似乎想成为你的XML文件。不过,从控制台输出,它看起来像你的url变量设置为这样的:这里

http://theaggie.org/article/2011/04/07/federal-government-cites-uc-davis-for-animal-cruelty 

我这么想吗?这应该是这样吗?

+0

嗨esqew! 非常感谢您的回复。我认为变量url是正确定义的。我想在控制台上记录该特定的网址。它在控制台上登录,但由于错误代码为-1000,我们的解析器无法连接到链接。 如果我将它发送到您的私人电子邮件,您是否介意查看我们的代码?再次感谢。 – SerPiero 2011-04-13 06:17:06

+0

您应该仔细检查。这似乎很奇怪,你的网址被设置为别的东西*除了你的XML feed。 – esqew 2011-04-13 19:32:16

+0

再次嗨。我们已经解析了XML Feed。现在,我们试图进入每个链接并解析HTML的“BODY”。 – SerPiero 2011-04-14 00:27:57

在我的案例问题是在第三方库 - FirebasePerformance。 问题网址:https://github.com/firebase/firebase-ios-sdk/issues/486