URLRequest HTTP POST method performs a GET instead

The following code snippet does not work as expected:

var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = bodyData
request.httpMethod = "POST"

The code sends a GET request to a local server and since I have control of that server, I can see an error message as the server expects a POST rather than the GET. What do I need to change so that the above code actually performs a POST? Thanks in advance!

URLRequest HTTP POST method performs a GET instead
 
 
Q