I am using the code below to make a URLRequest but specials characters, like &, aren't being encoded correctly. What am I doing wrong?
var request = URLRequest(url: URL(string: "http://\(hostToUse)/user/login")!)
request.httpMethod = "POST"
request.timeoutInterval = 120.0
var postString = "data={\"userName\":\"\(username)\",\"password\":\"\(password)\"}"
postString = postString.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
postString = postString.replacingOccurrences(of: " ", with: "")
request.httpBody = postString.data(using: .utf8, allowLossyConversion: false)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")