我有一个URL,我试图从中获取XML。NSURLConnection返回无数据
现在在我的iOS应用程序,我有这个,获取数据。
- (void)viewDidLoad {
[super viewDidLoad];
[self loadDataUsingNSURLConnection];
}
- (void) loadDataUsingNSURLConnection {
NSString *url = @"http://64.182.231.116/~spencerf/university_of_albany/u_albany_alumni_menu_test.xml";
[self getMenuItems:url];
}
然后终于此,
- (void)getMenuItems:(NSString*)url{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"response == %@", response);
NSLog(@"data: %@", data);
/*
self.mealdata=[[MealData alloc]init:data];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self.loadingView removeFromSuperview];
});
*/
}];
}
现在有时当我运行我的应用程序它的伟大工程,并返回数据,但后来有时候,我会说的时候约25%,与我改变运行之间的任何内容。它没有返回数据,并NSLog
回报
2015-03-10 18:28:05.472 APP[6289:97905] response == <NSHTTPURLResponse:
0x7fee7628e000> { URL: http://64.182.231.116/~spencerf/university_of_albany/u_albany_alumni_menu_test.xml } { status code: 200, headers {
"Accept-Ranges" = bytes;
Connection = "Keep-Alive";
"Content-Length" = 0;
"Content-Type" = "application/xml";
Date = "Tue, 10 Mar 2015 22:28:04 GMT";
Etag = "W/\"218ceff-0-510f6aa0317dd\"";
"Keep-Alive" = "timeout=5, max=90";
"Last-Modified" = "Tue, 10 Mar 2015 22:28:03 GMT";
Server = Apache;
} }
2015-03-10 18:28:05.472 App[6289:97905] data: <>
不知道为什么发生这种情况,我不能告诉它工作时,当它没有什么改变之间的区别?所以我不知道如何解决这个问题?
我想要的是每次都得到数据吗?
感谢您的帮助。
我在你的网址上得到了一个404 – 2015-03-17 20:17:29