从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]; 
} 
+0

实际上,数据是在'else'之后的大括号'{}'中返回的。如果你根本不使用它,你什么都看不到。还要考虑到'URLSession'异步工作。 – vadian

你在控制台下面让错误打印数据?

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。

请看下面的问题来了解添加异常。

Transport security blocked

更新:

上面的网址给XML响应,请参阅以下链接XML解析

xml parsing in ios tutorial

+0

不......不是......我加入了plist。没有得到数据和响应使用宝它说使用“​​宝数据”它说错误:使用未声明的标识符'数据'错误:1错误解析表达式 – Nishanth

+0

我试过上面的代码,并得到了一个XML响应。请使用NSXMLParser解析xml文件。 – Dili

+0

@Nishanth仍然收到空白的数据? – Dili

也许你可以在“其他设置断点“分支。当数据返回时,它会触发断点,使用”po数据“。