我正在 Xcode 6.1、iOS 8.1 中开发一个应用程序;该应用程序直到 2 天前都工作得很好,但今天当我执行它时,我在网络服务中遇到了错误,错误打印在下面。
错误:错误域=NSURLErrorDomain代码=-1001“请求计时
出。” UserInfo=0x7c6899b0 {NSErrorFailingURLStringKey=,
NSErrorFailingURLKey=, NSLocalizedDescription=请求定时
out., NSUnderlyingError=0x7c688f60“请求超时。”}
我使用 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);
}];
}
更新:我已经退出/重新启动了 iOS Simulator.app,恢复了内容和设置,但没有任何效果。
代码中没有任何问题。我猜想模拟器内部无法连接到互联网,所以这就是为什么它在提供各种超时间隔后无法连接到服务器。但当我另一天执行时,它工作得很好。感谢@Andrew Jaffee 帮助我找到这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)