【发布时间】:2012-09-14 17:21:20
【问题描述】:
我使用 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);
}
它最终调用了这个网址http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123
但是当我在浏览器中点击这个 url 时它工作正常,但是在我的应用程序中我得到了这个错误
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
请帮我看看可能是什么问题
【问题讨论】:
-
你是在设备上还是在模拟器上测试这个?
标签: iphone .net ios nsurlconnection