iphone - 获取错误域=NSURLErrorDomain 代码=-1004 "Could not connect to the server."

标签 iphone .net ios nsurlconnection

我使用 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);
}

它最终调用了这个 url http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123

但是当我在浏览器中点击这个 url 时它工作正常,但是在我的应用程序中我收到了这个错误

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

请帮我看看有什么问题

最佳答案

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

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

应该可以更轻松地进行故障排除。

关于iphone - 获取错误域=NSURLErrorDomain 代码=-1004 "Could not connect to the server.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429192/

相关文章:

iphone - 更新导航栏

iphone - 无法在 iPhone 或 Mac 上播放 wav 音频文件

c# - 按两列分组并使用元组作为键 C# Linq 执行 ToDictionary

c# - Process.WaitForExit 跨机器不一致

ios - 同步更新 UITableView 的模式?

ios - 如何将自定义导航栏链接到导航 Controller ?

iphone - iPad : new 4/5 finger multitasking gestures - when is the app's screenshot taken?

iphone - Mac 自动调整 NSView 保持纵横比

c# - 如何检查枚举标志是否与另一个枚举一起升起?

ios - 在没有后退按钮的情况下推送到 ViewController