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