Alamofire 3 Custom Encoding To Alamofire 4 Custom Encoding

后端 未结 3 1773
天命终不由人
天命终不由人 2021-02-15 23:16

I have method writing in Alamofire 3 with customParameterEncoding. This custom encoding just replaces \"[]=\" with \"=\" in queryString and returns it.

Alamofire         


        
3条回答
  •  遇见更好的自我
    2021-02-15 23:47

    In Alamofire 4.0 you should use ParameterEncoding.

    struct CustomEncoding: ParameterEncoding {
        func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
            var request = try! URLEncoding().encode(urlRequest, with: parameters)
            let urlString = request.url?.absoluteString.replacingOccurrences(of: "%5B%5D=", with: "=")
            request.url = URL(string: urlString!)
            return request
        }
    }
    

提交回复
热议问题