NSURLErrorDomain代码= -1005"网络连接丢失

时间:2016-02-15 14:24:42

标签: ios xcode nsurlconnection nsmutableurlrequest nserror

当我呼叫服务时,它会给出以下错误响应。

我做了google并重新启动了Xcode和模拟器。它不适合我。即使在设备中,我也面临同样的问题。任何人都可以帮助我。

服务电话:

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", urlString,paramsString]];
    theRequest = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0];

    if (paramsString!=nil)
    {
        NSString *msgLength = [[NSString alloc]initWithFormat:@"%lu",(unsigned long)[paramsString length]];
        [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    }
    [theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [theRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    [theRequest setValue:[NSString stringWithFormat:@"authToken=%@",self.authToken] forHTTPHeaderField:@"Cookie"];

    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (theConnection)
    {
        self.receivedData=[[NSMutableData alloc] init];
    }

错误:

Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x7c3770a0 {NSErrorFailingURLStringKey=serviceUrl, _kCFStreamErrorCodeKey=-4, NSErrorFailingURLKey=serviceUrl, NSLocalizedDescription=The network connection was lost., _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x79769170 "The network connection was lost."}

1 个答案:

答案 0 :(得分:0)

您的Web服务是否符合应用传输安全指南?

如果不是,您应该禁用它,或者至少将其配置为与您的应用配合使用。

教程:Tutorial