I wanna give Alamofire request with the following
var postParameters=[
"x" : "value1",
"y" : "value2",
"y" : "value3"
]
How do I achieve this?.
I can't give it as any collection. I am in need to give it as a separate parameters only.
Any hint will be helpful for me. Thanks in advance.

While there is no possible way of creating a dictionary with duplicate keys, there is a way to pass these kind of parameters to your server by using an array:
let postParameters: [String: Any] = [
"x" : "value1",
"y" : ["value2", "value3"]
]
then when you call request function of Alamofire, you pass a new instance of URLEncoding as encoding parameter and specify the way that you want to encode arrays, like this:
AF.request(
"url",
method: .post,
parameters: postParameters,
encoding: URLEncoding(arrayEncoding: .noBrackets)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With