I am working on the APIs. I face an issue in the Alamofire put a request that contains the parameter(string and JSON format) and encoder(image attached).
Here is the code
func updateAfterTask(task_id: String, after_image_id: String){
let token=UserDefaults.standard.string(forKey: "token") ?? "nil"
let headers: HTTPHeaders = [.authorization(bearerToken: token)]
var data = Dictionary<String,String>()
data["after_image"] = after_image_id
var parameters = Dictionary<String,Any>()
parameters["task_id"] = task_id as! String
parameters["data"] = data as! Dictionary<String, String>
let request = AF.request("http://bktotaal.epicapps.nl:2019/private/updateTask", method: .put, parameters: parameters,encoder: URLEncodedFormParameterEncoder.default,headers: headers)
request.responseJSON { response in
switch response.result {
case let .success(value):
if let JSON = value as? [String: Any] {
print("Create Task Response", value)
UserDefaults.standard.removeObject(forKey: "taskimage")
UserDefaults.standard.synchronize()
self.presentationMode.wrappedValue.dismiss()
}
case let .failure(error):
print("Create Task Error")
print(error)
}
}
}
When I removed the encoder then the issue remove. Does anyone know how to resolve the issue?
Here is the postman image
question from:
https://stackoverflow.com/questions/65644824/alamofire-put-request-with-enconder 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…