Request Timed out with Code

时间:2017-06-15 09:54:37

标签: ios swift request alamofire connection-timeout

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.}

Am getting this response calling MY API.. am using alamofire to call the api.. Is any problem in alamofire or local API

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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.

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.