Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.66 KB | None | 0 0
  1. var request = URLRequest(url: URL(string: "var request = URLRequest(url: URL(string:"http://www.thisismylink.com/postName.php")!)
  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()")!)
  20. request.httpMethod = "POST"
  21. let postString = "id=13&name=Jack"
  22. request.httpBody = postString.data(using: .utf8)
  23. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  24.    guard let data = data, error == nil else {                                                 // check for fundamental networking error
  25.        print("error=\(error)")
  26.        return
  27.    }
  28.  
  29.    if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {           // check for http errors
  30.        print("statusCode should be 200, but is \(httpStatus.statusCode)")
  31.        print("response = \(response)")
  32.    }
  33.  
  34.    let responseString = String(data: data, encoding: .utf8)
  35.    print("responseString = \(responseString)")
  36. }
  37. task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement