@IBAction func send(_ sender: Any) {
let postString = "c=\(Pw.text!)&d=\(Email.text!)"
let request = NSMutableURLRequest(url: NSURL(string: "http://www.hscrent.com/....php")! as URL)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
(data, response, error) -> Void in
if let unwrappedData = data {
do {
let tokenDictionary:NSDictionary = try JSONSerialization.jsonObject(with: unwrappedData, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSDictionary
let token = tokenDictionary["...."] as? String
print(tokenDictionary)
}
catch {
DispatchQueue.main.async { // Correct
self.Email.text = ""
self.Pw.text = ""
}
let alertView = UIAlertController(title: "Login failed", message: "Wrong username or password." as String, preferredStyle:.alert)
let okAction = UIAlertAction(title: "Try Again!", style: .default, handler: nil)
alertView.addAction(okAction)
self.present(alertView, animated: true, completion: nil)
return
}
}
}
task.resume()
}
}
I've tried that and its still not working.