i calling web service from my ios app using NSURLConnection. here is my code
#define kBaseServerUrl @"http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/"
#define kProductServiceUrl @"Products"
-(void)callService{
NSURL *url;
if (currState == ProductServiceState) {
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kProductServiceUrl,[self getRevisionNumberForProduct]]];
}
else if(currState == TankStrickerServiceState){
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kTankStrickerServiceUrl,[self getRevisionNumberForTankStricker]]];
}else if(currState == CalculationServiceState){
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kCalculationServiceUrl,[self getRevisionNumberForCalculation]]];
}else{
//Future Use
}
NSLog(@"%@",[url absoluteString]);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
NSLog(@"%@",urlConnection);
}
Its end up calling this url http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123
but when i hit this url in browser its working fine, but in my app i m getting this error
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
Please help me what might be problem
Looks like you are setting it up right, I would suspect something regarding your objects - try calling a hard coded URL by replacing your existing URL request with:
NSURLRequest *urlRequest = [NSURLRequest
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
Should make troubleshooting this much easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With