sac*_*hin 10 .net iphone nsurlconnection ios
我使用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);
}
Run Code Online (Sandbox Code Playgroud)
它最终称这个网址为http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123
但是当我在浏览器中点击这个网址它工作正常,但在我的应用程序中我得到这个错误
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
Run Code Online (Sandbox Code Playgroud)
请帮我解决可能存在的问题
看来您的设置正确,我怀疑有关您的对象的某些内容 - 尝试通过将现有的 URL 请求替换为以下内容来调用硬编码的 URL:
NSURLRequest *urlRequest = [NSURLRequest
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
Run Code Online (Sandbox Code Playgroud)
应该会使故障排除更加容易。
| 归档时间: |
|
| 查看次数: |
18154 次 |
| 最近记录: |