从Web服务
问题描述:
没有得到数据,而尝试使用po data
它说从Web服务
error: use of undeclared identifier 'data'
error: 1 errors parsing expression
-(void)viewWillAppear:(BOOL)animated {
NSMutableURLRequest*req=[[NSMutableURLRequest alloc]init];
NSURL*url=[NSURL URLWithString:@"http://www.thomas-bayer.com/sqlrest/CUSTOMER/"];
[req setURL:url];
[[[NSURLSession sharedSession]dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error){
NSLog(@"error");
}else{}
}] resume];
}
答
你在控制台下面让错误打印数据?
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
我觉得你必须为“http:”url配置App Transport Security Exception。
请看下面的问题来了解添加异常。
更新:
上面的网址给XML响应,请参阅以下链接XML解析
答
也许你可以在“其他设置断点“分支。当数据返回时,它会触发断点,使用”po数据“。
实际上,数据是在'else'之后的大括号'{}'中返回的。如果你根本不使用它,你什么都看不到。还要考虑到'URLSession'异步工作。 – vadian