Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. var request = URLRequest(url: URL(string: "http://35.162.69.72/school-news/index.php/api/v1/login")!)
  2. request.httpMethod = "POST"
  3. let postString = "username=domy@libero.it&password=curuta15"
  4. request.httpBody = postString.data(using: .utf8)
  5. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  6. guard let data = data, error == nil else { // check for fundamental networking error
  7. print("error=\(error)")
  8. return
  9. }
  10.  
  11. if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
  12. print("statusCode should be 200, but is \(httpStatus.statusCode)")
  13. print("response = \(response)")
  14. }
  15.  
  16. let responseString = String(data: data, encoding: .utf8)
  17. print("responseString = \(responseString)")
  18. }
  19. task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement