Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "firstName": req.body.firstName,
- "lastName": req.body.lastName,
- "email": req.body.email,
- "role": req.body.role,
- "birthday": new Date(req.body.birthday),
- "sex": req.body.sex,
- "password": pw
- }
- func putUser(accessToken: String, refreshToken: String, emailCurrent: String, firstName: String, lastName: String, emailNew: String,
- role: Int, sex: String, password: String){
- print("vi kører putUser med denne accessToken (accessToken) og refreshToken (refreshToken)")
- let urlPath = "http://xxxxxxxxxxxxxx/api/users/user/(emailCurrent)"
- let url = NSURL(string: urlPath)
- let session = URLSession.shared
- let request = NSMutableURLRequest(url: url as! URL)
- request.addValue(accessToken, forHTTPHeaderField: "accessToken")
- request.addValue(refreshToken, forHTTPHeaderField: "refreshToken")
- request.httpMethod = "PUT"
- let postString = "firstName=(firstName)&lastName=(lastName)&email=(emailNew)&role=(role)&birthday=2010-09-08&sex=(sex)&password=(password)"
- // let strinng = "firstName=(firstName)&lastName=(lastName)&email(emailNew)&role=(role)&birthday=2010-09-08&sex=(sex)&password=(password)"
- print()
- print()
- print("Here is postString from putUser: (postString)")
- request.httpBody = postString.data(using: String.Encoding.utf8)
- let task = session.dataTask(with: request as URLRequest, completionHandler: {data, response, error -> Void in
- print("Task completed (data) and response is xxxx")
- // print all info as a string. ---
- let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
- print("responseString = (responseString!)")
- })
- task.resume()
- }
- Here is postString from putUser:
- firstName=abcd&lastName=bb&email=abc@gmail.com&role=1&birthday=2010-09-08&sex=female&password=123
- Task completed Optional(169 bytes) and response is xxxx
- 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