Error: Error Domain=NSURLErrorDomain Code=-1001 “T

2019-01-07 22:35发布

I am working on an application in Xcode 6.1, iOS 8.1; the application was working completely fine till 2 days before, but today as I executed it I got an error in the web service & the error is printed below.

Error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x7c6899b0 {NSErrorFailingURLStringKey=, NSErrorFailingURLKey=, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x7c688f60 "The request timed out."}

I had used AFNetworking 2.x and following code snippet to make network call:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes=[manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

[manager POST:<URL>
   parameters:<parameters>
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          NSLog(@"JSON: %@", responseObject);
          NSError *error = nil;
          NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
          if (error) {
              NSLog(@"Error serializing %@", error);
          }
          NSLog(@"Dictionary %@", JSON);
          NSLog(@"Success");
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }]; 
}

UPDATE: I had done quit/relaunched the iOS Simulator.app, reseted content & settings, but nothing worked.

5条回答
劳资没心,怎么记你
2楼-- · 2019-01-07 22:57

There was no issue in the code. I guess the simulator internally was not able to connect to the internet, so that is why it was not able to connect to the server after providing various timeout intervals. But it worked completely fine when I executed another day. Thanks to @Andrew Jaffee for helping me to find this issue.

查看更多
Viruses.
3楼-- · 2019-01-07 23:07

I was calling local server connection and was getting this error. I was using different network in my device and phone. When I connected both to same wifi, it worked.

查看更多
你好瞎i
4楼-- · 2019-01-07 23:07

This can happen if your network configuration changes while the simulator is running. Please reboot the simulator runtime (eg: quit/relaunch the iOS Simulator.app) and that will likely fix your problem.

If the problem persists, please update your question to indicate that the issue you are experiencing is not this known problem. Thanks.

查看更多
做个烂人
5楼-- · 2019-01-07 23:11

iOS Simulator -> Reset Content and Settings; worked for me

查看更多
你好瞎i
6楼-- · 2019-01-07 23:14

Had this problem and had a different resolution so I thought I'd add it here:

Basically, I was sending some parameters when it should have been a clean GET request. Deleted the parameters, GET request worked just fine.

查看更多
登录 后发表回答