对于iOS 7+和OS X 10.9+使用:
NSURLSession *aSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[aSession dataTaskWithURL:[NSURL URLWithString:@"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (((NSHTTPURLResponse *)response).statusCode == 200) {
if (data) {
NSString *contentOfURL = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", contentOfURL);
}
}
}] resume];
对于早期版本的使用:
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (((NSHTTPURLResponse *)response).statusCode == 200) {
if (data) {
NSString *contentOfURL = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", contentOfURL);
}
}
}];
如果你正在寻找一个更容易实现解决方案看看this link
来源
2013-07-24 16:01:14
HAS
你可以发布你的网址的样本ta喜欢? –
它确实看起来像XML。 – Caleb