Error Domain=NSURLErrorDomain Code=-1005 “The network connection was lost.”

前端 未结 30 2978
悲哀的现实
悲哀的现实 2020-11-22 05:51

I have an application which works fine on Xcode6-Beta1 and Xcode6-Beta2 with both iOS7 and iOS8. But with Xcode6-Beta3, Beta4, Beta5 I\'m facing network issues with iOS8 but

相关标签:
30条回答
  • 2020-11-22 06:38

    I was experiencing this problem while using Alamofire. My mistake was that I was sending an empty dictionary [:] for the parameters on a GET request, rather than sending nil parameters.

    Hope this helps!

    0 讨论(0)
  • 2020-11-22 06:39

    If anyone is getting this error while uploading files to a backend server, make sure the receiving server has a maximum content size that is allowable for your media. In my case, NGINX required a higher client_max_body_size. NGINX would reject the request before the uploading was done so no error code came back.

    0 讨论(0)
  • 2020-11-22 06:40

    Whenever got error -1005 then need to call API Again.

    AFHTTPRequestOperationManager *manager = 
    [AFHTTPRequestOperationManager manager];
    [manager setSecurityPolicy:policy];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:<example-url>
       parameters:<parameteres>
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSLog(@“Success: %@", responseObject);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
          if (error.code == -1005) {
              // Call method again... 
           }
      }];
    

    You need to Add your code to call function again. MakeSure that you were call method once otherwise its call recursive loop.

    0 讨论(0)
  • 2020-11-22 06:42

    I was facing the same issue, I have enabled Network Link Conditioner for slow network testing for the app. That was creating this error some times, When i have disabled it from Settings > Developer > Network Link Conditioner, it solved my problem.

    Hope this help someone.

    0 讨论(0)
  • 2020-11-22 06:43

    My problem was on the server. I was using Python's BaseHTTPRequestHandler class and I wasn't sending a body in the response. My problem was solved when I put an empty body like the following.

    def do_POST(self):
        content_len = int(self.headers.get('Content-Length'))
        post_body = self.rfile.read(content_len)
        msg_string = post_body.decode("utf-8")
        msg_json = json.loads(msg_string)
        self.send_response(200)
        self.end_headers() #this and the following lines were missing
        self.wfile.write(b'') 
    
    0 讨论(0)
  • 2020-11-22 06:44

    I had to exit XCode, delete DerivedData folder contents (~/Library/Developer/Xcode/DerivedData or /Library/Developer/Xcode/DerivedData) and exit simulator to make this work.

    0 讨论(0)
提交回复
热议问题