我使用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
,但是當我打的網址,瀏覽器其工作正常,但在我的應用程序即時得到這個錯誤
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
請幫助我可能是什麼問題
您是在設備上還是在模擬器上測試這個? – Wasim
兩者都不起作用 – sachin