2012-09-14 16 views
10

NSURLConnectionを使用して、私のiosアプリケーションからWebサービスを呼び出しています。ここに私のコードがあるエラードメイン取得= NSURLErrorDomainコード= -1004 "サーバーに接続できませんでした。"

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

そのをしてくださいhttp://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123

このURLを呼び出すに終わるが、私は、ブラウザでこのURLを打ったときにその作業罰金が、私のアプリイムに

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

このエラーを取得問題の可能性があるものを手助けしてください

+0

デバイスまたはシミュレータでこれをテストしていますか? – Wasim

+0

両方が動作していない – sachin

答えて

2

あなたはそれを正しく設定しているように見えますが、私はあなたのオブジェクトに関する何かを疑うでしょう - あなたのe URLをリクエストしてください:

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

このトラブルシューティングをさらに簡単に行う必要があります。

+0

それは奇妙です、[NSURLRequestクラスのドキュメント](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class)で 'requestWithString'メソッドが見つかりません/Reference/Reference.html)...私を助けてくれますか? –

+0

私があなたに与えることができる最高のヘルプは、他の良いSOコードを指していると思います;-) http://stackoverflow.com/questions/19263186/nsurlrequest-creation-using-query-string-in-iosこのようにURLリクエストの例が作成されました。 – woody121

+1

@MaxGontarこれはありません。私は彼が '[NSURLRequest requestWithURL:[NSURL URLWithString:@" ... "]]'を意味したと思います。 – devios1