我对Alamofire URLEncoding有问题,特别是对于参数数组,其中使用[]分隔符来解析参数数组。
我如何为这个案例编写自己的URLEncoding?
最佳答案
试试这个获取:
struct CustomGetEncoding: ParameterEncoding {
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var request = try URLEncoding().encode(urlRequest, with: parameters)
request.url = URL(string: request.url!.absoluteString.replacingOccurrences(of: "%5B%5D=", with: "="))
return request
}
}
如何使用
Alamofire.request("url", method: .get, parameters: ["foo": ["bar1", "bar2"]], encoding: CustomGetEncoding()).validate().responseJSON { (response) in
}
关于ios - Alamofire的自定义URLEncoding,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44713429/