简体   繁体   中英

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 im 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM