Guest User

Untitled

a guest
May 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. @IBAction func nextButton(_ sender: Any) {
  2. ...
  3. ...
  4. } else if (counter == 3) {
  5.  
  6. let url = URL(string: "http://myserver.com/signup.php")!
  7. var request = URLRequest(url: url)
  8. request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
  9. request.httpMethod = "POST"
  10. let postString = "fname=(firstName)&lname=(lastName)&username=(username)&email=(email)&phone=(phone)&country=(country)&password=(password)"
  11. request.httpBody = postString.data(using: .utf8)
  12. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  13. guard let data = data, error == nil else { // check for fundamental networking error
  14. print("error=(String(describing: error))")
  15. return
  16. }
  17.  
  18. if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
  19. print("statusCode should be 200, but is (httpStatus.statusCode)")
  20. print("response = (String(describing: response))")
  21. }
  22.  
  23. let responseString = String(data: data, encoding: .utf8)
  24. print("responseString = (String(describing: responseString))")
  25. }
  26. task.resume()
  27.  
  28. }
Add Comment
Please, Sign In to add comment