1

When i'm calling service, it will give below error response.

I did google and restarted Xcode and simulator. its not working for me. even in device also i'm facing same issue. can any one help me.

Service calling:

    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:

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."}
Ravi
  • 888
  • 6
  • 24
  • Code looks dodgy. From `paramsString!=nil` I can see that `paramString` is optional and yet you've already used it to form the URL. Then you are using the length of the `paramString` as the `Content-Length`? – trojanfoe Feb 15 '16 at 14:27
  • @Ravi i have nsclass. it is very easy for WS calling using AFNetworking http://stackoverflow.com/questions/33767908/volunteermatch-api-objective-c/33886449#33886449 – Vvk Feb 16 '16 at 05:37

1 Answers1

0

Did your Webservice conforms to App Transport Security Guidelines ?

If not you should disable it, or at least configure it to work with your app.

tutorial : Tutorial

CZ54
  • 5,488
  • 1
  • 24
  • 39