我已经完成了以下代码,以便从击中api时获得的响应获取car_image。我有一个url作为关键car_image的值.Till,现在一切正常。
代码:
-(void)callService{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
NSMutableDictionary *dict = [NSMutableDictionary new];
[dict setValue:@561 forKey:@"did"];
[manager POST:@"http://demo.esenseit.in/Alec1-Admin-Panel-and-API/alec_api/index.php?flag=get_car_list" parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"response %@",responseObject);
responseArr = [responseObject valueForKey:@"data"];
NSString *urlstr=[[responseArr valueForKey:@"car_image"]objectAtIndex:1];
NSLog(@"value of urlstr %@",urlstr);
// NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlstr]];
NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlstr] options:NSDataReadingUncached error:&error];
if (error) {
NSLog(@"Error is %@", [error localizedDescription]);
} else {
NSLog(@"Data has loaded successfully.");
}
NSLog(@"value of url %@",[NSURL URLWithString:urlstr]);
NSLog(@"value of data %@",data);
dispatch_async(dispatch_get_main_queue(), ^{
});
}
failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {
NSLog(@"request failed %@",error);
}];
}
问题:
数据的值返回null。我无法理解string,url何时都能很好地返回它们的值,那么为什么只有数据才会创建null结果。
记录值:
1)value of urlstr demo.esenseit.in/Alec1-Admin-Panel-and-API/alec_api/upload/car_8_1514810479.jpg
2)Error is The file “car_8_1514810479.jpg” couldn’t be opened.
3)value of url demo.esenseit.in/Alec1-Admin-Panel-and-API/alec_api/upload/car_8_1514810479.jpg
4)value of data (null)