Hi, I'm trying to send a POST request within Swift and I cannot get it to work properly. I can send a generic GET request that seems to work fine but a POST request is giving me no end of grief.
This is what I have which works perfectly fine as a GET request.
guard let url = URL(string: "https://example.com/api/my-endpoint") else {
return
}
URLSession.shared.dataTask(with: url) { (data, response, error) in
let collection = try! JSONDecoder().decode(APIResponse.self, from: data!)
print(collection)
}.resume()
However, I need to send a POST request with two parameters; email
and id
but all of the tutorials and questions I've searched through on Google are just too complicated and go way over my head. I'm hoping someone can explain clearly how I can achieve this?