【问题标题】:NSURLConnection fails with error code -1001NSURLConnection 失败,错误代码 -1001
【发布时间】:2011-08-01 22:57:02
【问题描述】:

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

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

当我们尝试另一个网站时,它失败并显示错误代码 -1000,这意味着链接错误。这是那个网址

http://www.hiddenelephant.com/blog/feed/rss/

我知道我们的代码肯定有问题,但我们无法弄清楚。这是我第一次在 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!

【问题讨论】:

    标签: c xcode ipad interface-builder


    【解决方案1】:

    变量url 定义是否正确?如果我正确阅读了您的代码,您应该是 NSLog()ging 您的 url 变量,您似乎想成为您的 XML 文件。但是,从您的控制台输出来看,您的 url 变量似乎设置为:

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

    我在这里遗漏了什么吗?应该是这样吗?

    【讨论】:

    • 你好,esqew!非常感谢您的回复。我认为变量 url 定义正确。我想在控制台上记录那个特定的 url。它登录控制台,但由于错误代码 -1000,我们的解析器无法连接到链接。如果我将代码发送到您的私人邮箱,您介意看看我们的代码吗?再次感谢。
    • 您应该仔细检查。您的网址设置为除了您的 XML 提要之外的其他内容,这似乎有点奇怪。
    • 你好。我们已经解析了 XML 提要。现在,我们正在尝试进入每个链接并解析 HTML 的“BODY”。
    • 我认为我们的问题在于 NSURL 连接。我们在一个网站上收到错误代码 -1000,在另一个网站上收到错误代码 -1001。我们的一个怀疑是我们正在为 HTML 使用 Rss 解析器。
    【解决方案2】:

    在我的情况下,问题出现在第 3 方库 - FirebasePerformance。 问题地址:https://github.com/firebase/firebase-ios-sdk/issues/486

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多