简体   繁体   English

请求使用代码超时

[英]Request Timed out with Code

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x608000244a70 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://www.dfdd, NSErrorFailingURLKey=http://www.dfdd.com, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}

我得到这个响应调用MY API ..我正在使用alamofire来调用api ..在alamofire或本地API中有任何问题

You have to following solution. 你必须遵循解决方案。

  1. Connect with fast internet connection because your request carry heavy data. 连接快速互联网连接,因为您的请求携带大量数据。
  2. Set request timeout to session manager 将请求超时设置为会话管理器

    manager.session.configuration.timeoutIntervalForRequest = 120 manager.session.configuration.timeoutIntervalForRequest = 120

The main causes of this issue are either: 这个问题的主要原因是:

  1. The server is under heavy load, or does not have the resources to be able to respond in a timely fashion 服务器负载很重,或者没有足够的资源能够及时响应
  2. The users network connection is slow, and unable to download the response quick enough. 用户网络连接速度很慢,无法足够快地下载响应。

You should check your API & Server logs to look for any potential issues there, ensure there are no errors and that the API is capable of handling your requests as the app scales. 您应该检查您的API和服务器日志以查找那里的任何潜在问题,确保没有错误,并且API能够在应用程序扩展时处理您的请求。

Also, you should add some additional error handling in your application so that if this issue does occur, not only do you handle the case properly and show the user that an error occured (or retry) and also log/report the error so that you can respond to it and investigate. 此外,您应该在应用程序中添加一些额外的错误处理,以便在发生此问题时,不仅可以正确处理案例并向用户显示错误发生(或重试),还可以记录/报告错误,以便您可以回应并调查。

Sometimes users connections will drop due to loss of mobile signal or other reasons so you need to handle this gracefully. 有时用户连接会因移动信号丢失或其他原因而丢失,因此您需要优雅地处理此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM