Alamofire.request(.GET,SearchURL,parameters: params,enCoding: customEnCoding,headers: headers).valIDate().responseJsON { response in switch response.result { case .success: print("success") break case .failure(let error): print("Error: " + error.localizedDescription) break } }
和自定义编码参数
let customEnCoding = ParameterEnCoding.Custom { requestConvertible,parameters in let (mutableRequest,error) = ParameterEnCoding.URL.encode(requestConvertible,parameters: parameters) mutableRequest.URL = NSURL(string: mutableRequest.URLString.stringByReplacingOccurrencesOfString("%5B%5D=",withString: "=")) return (mutableRequest,error)}
如何将customEnCoding转换为Alamofire 4版本?
解决方法 在Alamofire 4.0中,您应该使用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 }}总结
以上是内存溢出为你收集整理的swift – Alamofire 3自定义编码到Alamofire 4自定义编码全部内容,希望文章能够帮你解决swift – Alamofire 3自定义编码到Alamofire 4自定义编码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)