Advertisement
Guest User

amamput

a guest
Mar 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. let url = NSURL(string: "https://yourUrl.com") //Remember to put ATS exception if the URL is not https
  2. let request = NSMutableURLRequest(URL: url!)
  3. request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") //Optional
  4. request.HTTPMethod = "PUT"
  5. let session = NSURLSession(configuration:NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: nil, delegateQueue: nil)
  6. let data = "username=self@gmail.com&password=password".dataUsingEncoding(NSUTF8StringEncoding)
  7. request.HTTPBody = data
  8.  
  9. let dataTask = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
  10.  
  11. if error != nil {
  12.  
  13. //handle error
  14. }
  15. else {
  16.  
  17. let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
  18. print("Parsed JSON: '\(jsonStr)'")
  19. }
  20. }
  21. dataTask.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement