Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

swiftui - Alamofire put request with enconder

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).

Issue image

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 enter image description here

question from:https://stackoverflow.com/questions/65644824/alamofire-put-request-with-enconder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...