繁体   English   中英

获取错误域= NSURLErrorDomain代码= -1004“无法连接到服务器”。

[英]Getting Error Domain=NSURLErrorDomain Code=-1004 “Could not connect to the server.”

我使用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

但是当我在浏览器中点击这个网址它工作正常,但在我的应用程序中我得到这个错误

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

请帮我解决可能存在的问题

看起来你正确的设置,我怀疑你的对象有什么 - 尝试通过用以下内容替换现有的URL请求来调用硬编码的URL:

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

应该更容易进行故障排除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM