I use the moya make the post request,but when I send the post , the server give me an error, it can't decoding the body parameters.I use URLEncoding.default to encode the parameters like this
public var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}
It will set the content-type application/x-www-form-urlencoded, and the server accept content type is same too
if parameters is a dictionary like this {"a":"b"} ,that is working well, but if dictionary contained array or another dictionary ,the server can't get the parameters from request body.
EX:
{
"a":"xxx",
"b":[
"xxxxx",
"xxxxx"
]
}
alamofire will encode this like "a"="xxx"&b[]=xxxx&b[]=xxx
but the server expect a=xxx&b[0]=xxx&b[1]=xxxx
how to solve this problem ?
You can build the parameter string manually, and then link the parameter string to Url string. Finally, just make request with url by Alamofire, without any parameters(they are in url already).
The way to build parameter string: