Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."

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

like image 792
sachin Avatar asked Sep 14 '12 17:09

sachin


1 Answers

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.

like image 200
woody121 Avatar answered Oct 05 '22 04:10

woody121