Guest User

Untitled

a guest
Oct 15th, 2017
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. let postData = NSMutableData(data: "username=james+jypsee@jypsee.com".data(using: .utf8)!)
  2. postData.append("&password=redacted".data(using: .utf8)!)
  3. postData.append("&grant_type=password".data(using: .utf8)!)
  4. postData.append("&client_id=redacted".data(using: .utf8)!)
  5. postData.append("&client_secret=redacted".data(using: .utf8)!)
  6.  
  7. let request = NSMutableURLRequest(url: NSURL(string: "https://redacted.com/api/oauth2/token/")! as URL,
  8. cachePolicy: .useProtocolCachePolicy,
  9. timeoutInterval: 10.0)
  10. request.httpMethod = "POST"
  11. request.allHTTPHeaderFields = headers
  12. request.httpBody = postData as Data
  13. let session = URLSession.shared
  14. let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  15. if (error != nil) {
  16. print(error)
  17. } else {
  18. let httpResponse = response as? HTTPURLResponse
  19. print(httpResponse)
  20. }
  21. })
Add Comment
Please, Sign In to add comment