Advertisement
Guest User

Untitled

a guest
Jan 26th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. {
  2. "firstName": req.body.firstName,
  3. "lastName": req.body.lastName,
  4. "email": req.body.email,
  5. "role": req.body.role,
  6. "birthday": new Date(req.body.birthday),
  7. "sex": req.body.sex,
  8. "password": pw
  9. }
  10.  
  11. func putUser(accessToken: String, refreshToken: String, emailCurrent: String, firstName: String, lastName: String, emailNew: String,
  12. role: Int, sex: String, password: String){
  13.  
  14. print("vi kører putUser med denne accessToken (accessToken) og refreshToken (refreshToken)")
  15.  
  16. let urlPath = "http://xxxxxxxxxxxxxx/api/users/user/(emailCurrent)"
  17. let url = NSURL(string: urlPath)
  18. let session = URLSession.shared
  19. let request = NSMutableURLRequest(url: url as! URL)
  20. request.addValue(accessToken, forHTTPHeaderField: "accessToken")
  21. request.addValue(refreshToken, forHTTPHeaderField: "refreshToken")
  22. request.httpMethod = "PUT"
  23.  
  24.  
  25.  
  26. let postString = "firstName=(firstName)&lastName=(lastName)&email=(emailNew)&role=(role)&birthday=2010-09-08&sex=(sex)&password=(password)"
  27.  
  28.  
  29.  
  30. // let strinng = "firstName=(firstName)&lastName=(lastName)&email(emailNew)&role=(role)&birthday=2010-09-08&sex=(sex)&password=(password)"
  31.  
  32. print()
  33. print()
  34.  
  35. print("Here is postString from putUser: (postString)")
  36.  
  37. request.httpBody = postString.data(using: String.Encoding.utf8)
  38.  
  39.  
  40.  
  41. let task = session.dataTask(with: request as URLRequest, completionHandler: {data, response, error -> Void in
  42. print("Task completed (data) and response is xxxx")
  43.  
  44. // print all info as a string. ---
  45. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  46. print("responseString = (responseString!)")
  47.  
  48.  
  49.  
  50. })
  51. task.resume()
  52.  
  53. }
  54.  
  55. Here is postString from putUser:
  56. firstName=abcd&lastName=bb&email=abc@gmail.com&role=1&birthday=2010-09-08&sex=female&password=123
  57. Task completed Optional(169 bytes) and response is xxxx
  58. responseString = <!DOCTYPE html><html><head><title></title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Unexpected token f</h1><h2></h2><pre></pre></body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement