How do I call this php post request with swift?
I followed many tutorials, but it never worked.
My current try looks like this, but it doesn't work:
let request = NSMutableURLRequest(url: NSURL(string: "https://example.com/lovetanks/setGabriel.php")! as URL)
request.httpMethod = "POST"
let postString = "kiss=\(kiss)&cuddle=\(cuddle)&talk=\(talk)&chat=\(chat)"
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
print("error=\(String(describing: error))")
return
}
}
task.resume()
When I just do it with my browser I type:
https://example.com/lovetanks/setName.php?kiss=2&cuddle=1&talk=3.5&chat=7.876
Has any of you an idea?