10

NSURLConnection を使用して iOS アプリから Web サービスを呼び出しています。ここに私のコードがあります

#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);
}

このURLを呼び出すことになります http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123

しかし、ブラウザでこのURLにアクセスすると正常に動作しますが、アプリではこのエラーが発生します

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

何が問題なのか教えてください

4

1 に答える 1

2

あなたはそれを正しく設定しているように見えます。私はあなたのオブジェクトに関して何かを疑っています.既存のURLリクエストを次のように置き換えて、ハードコードされたURLを呼び出してみてください:

NSURLRequest *urlRequest = [NSURLRequest 
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];

これにより、トラブルシューティングがはるかに簡単になります。

于 2013-03-25T23:12:49.160 に答える