This is my code. It's working with POST but not with PUT.
let url:NSURL = NSURL(string: urlApi)!
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "PUT"
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
request.addValue("a5f96d8c01000194c639d6b5f3b199eb", forHTTPHeaderField: "token")
request.addValue("application/json", forHTTPHeaderField: "Accept")
let params:[String: AnyObject] = ["id" : 296,"name" : "asdad","space_width":10,"space_height":10,"space_altitude":10,"actions":""]
request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions())
let task = session.dataTaskWithRequest(request) {
(
let data, let response, let error) in
guard let _:NSData = data, let _:NSURLResponse = response where error == nil else {
print("error")
return
}
let dataString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(dataString)
}
task.resume()