问题
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
回答1:
You have to following solution.
- Connect with fast internet connection because your request carry heavy data.
Set request timeout to session manager
manager.session.configuration.timeoutIntervalForRequest = 120
回答2:
The main causes of this issue are either:
- The server is under heavy load, or does not have the resources to be able to respond in a timely fashion
- 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.
来源:https://stackoverflow.com/questions/44564422/request-timed-out-with-code