When Swift uses Alamofire to pass recursive arguments, an error is raised and a timeout is indicated, with the following main error message.
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1001 “The request timed out.” UserInfo={NSUnderlyingError=0x60000024bfa0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 “(null)” UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=Address of your request, NSErrorFailingURLKey=Address of your request址, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}
My main request code.
func NetworkMain(URL: String, paras: Parameters,method: HTTPMethod,finishedCallback:@escaping (_result:JSON)->()){ //let paras: Parameters = ["exFlag":"3","PhotoID" : photoID] let requestAttr = Alamofire.request(URL, method: method, parameters: paras, encoding: JSONEncoding.default, headers: heads).responseData{ The following code is omitted...
Because alamofire is used for the first time, the example is copied from others. I have been wondering why it is normal not to pass parameters, and data cannot be obtained normally when parameters are passed. No one has encountered this problem on the Internet. After repeatedly checking the format of parameters and the version of alamofire, it is found that there is no problem
Finally, check alamofire’s GitHub instructions and find that there are many encoding types of parameters. Well, that’s the problem encoding: JSONEncoding.default Change to encoding: URLEncoding.default , Request succeeded
Parameter can specify multiple encoding types. If you are interested, please refer to the description document of alamofire
Similar Posts:
- [Solved] iOS – NSURLConnection finished with error – code -1002
- JavaWeb HttpServletRequest (How to Get Line, Header and Body)
- After the JVM is started, setting the system property file.encoding again cannot affect the default encoding of the system & sun.jnu.encoding
- XHR request status is the solution to failed
- Solution to the problem of missing URI path in chrome 85 + referer
- Uncaught typeerror: the solution of illegal invocation problem
- TypeError: the JSON object must be str, not ‘bytes’
- How to Solve .Net 5 webapi cross domain Issue
- [Solved] Axios Cross-domain issues: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.