Present code :
let baseUrl = "abc.com/search/"
let param = [
"page":"1",
"size":"5",
"sortBy":"profile_locality"
]
let headers = [
"Content-Type": "application/json"
]
Alamofire.SessionManager.default.request("\(baseUrl)field", method: .post,parameters: param, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
print(response.request ?? "no request") // original URL request
if(response.response?.statusCode != nil){
print("done")
if self.checkResponse(response.response!.statusCode){
let json = JSON(data: response.data!)
//print("at_LeadStop json \(json)")
return completionHandler(json, false)
} else {
return completionHandler(JSON.null, true)
}
} else {
print("gone")
return completionHandler(JSON.null, true)
}}
I don't know how to add body request through this code. Please help me to slove this problem.
You are mixing two things here,
page
,size
andsortBy
is you need to pass with the url string as query string. Now your body is request isJSON
Array and you can post array withAlamofire
only usingURLRequest
. So try like this.Try this: Using Custom Encoding
Calling