我正在
Xcode 6.1,iOS 8.1中应用程序;该应用程序在两天之前完全正常工作,但是当我执行它时,我在Web服务和错误将在下面打印出来.
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.”}
我使用AFNetworking 2.x和以下代码片段进行网络调用:
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); }]; }
解决方法
代码中没有问题.我想这个模拟器内部无法连接到互联网,所以这就是为什么在提供各种超时时间后才能连接到服务器.但是当我执行另一天时,它工作完全正常.感谢@Andrew Jaffee帮助我找到这个问题.