I want to send json service when the user search text on searchbar. Here the issue is that I return null value of NSData object, what the issue is here? If I define the same url which I print in console that works but what’s the issue here?
-(void)doIt{
NSURL *url = [NSURL URLWithString:weburls];
NSData *data =[NSData dataWithContentsOfURL:url];
[self getData:data];
}
If I will write like that then it works, but I want to call the service on the searchbar event but there is a problem
NSString *weburl = [NSString stringWithFormat:@"%@%@",
@"http://192.168.1.196/ravi/iphonephp?mname=",searchText];
NSLog(@"%@",weburl);
NSURL *url = [NSURL URLWithString:weburl];
NSLog(@"the url is : %@",url);
NSError *error;
NSData *data =[NSData dataWithContentsOfURL:url options:nil error:&error];
NSLog(@"Data is :%@",data);
NSLog(@"the Error massage is : %@",error);
[self getData:data];
Gives me console value like
customCellDemo[1553:f803] the url is : http://192.168.1.196/ravi/iphonephp?mname=a
2012-03-16 15:26:36.259 customCellDemo[1553:f803] Data is :(null)
2012-03-16 15:26:43.624 customCellDemo[1553:f803] the Error massage is : Error
Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
UserInfo=0x6ab2760 {NSURL=http://192.168.1.196/ravi/iphonephp?mname=a}
From the manual of dataWithContentsOfURL;
In other words, it can either not create an NSData (unlikely) or it can probably not get any data from your supplied URL. I suggest you try to use
dataWithContentsOfURL:options:error:instead to get an error code and be able to diagnose the problem.