Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let url = NSURL(string: "https://yourUrl.com") //Remember to put ATS exception if the URL is not https
- let request = NSMutableURLRequest(URL: url!)
- request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") //Optional
- request.HTTPMethod = "PUT"
- let session = NSURLSession(configuration:NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: nil, delegateQueue: nil)
- let data = "username=self@gmail.com&password=password".dataUsingEncoding(NSUTF8StringEncoding)
- request.HTTPBody = data
- let dataTask = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
- if error != nil {
- //handle error
- }
- else {
- let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
- print("Parsed JSON: '\(jsonStr)'")
- }
- }
- dataTask.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement