Swift(or objective-c) equivalent of curl request Swift(or objective-c) equivalent of curl request curl curl

Swift(or objective-c) equivalent of curl request


I've got the auth token by using NSURLSession on behalf of NSURLConnection, however I am still not sure why NSURLSession can be used and NSURLConnection cannot be used.If you have an idea, please tell me. Thank you for your kindness.

func authentication2(){    let request = NSMutableURLRequest(URL: NSURL(string: "https://~~~/v2/authenticate/api")!)    request.HTTPMethod = "POST"    var loginID = "mylogin_id"    var apiKey = "myapi_key"    var postString:NSString = "login_id=\(loginID)&api_key=\(apiKey)"    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {        data, response, error in        if error != nil {            println("error=\(error)")            return        }        println("response = \(response)")        let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)        println("responseString = \(responseString)")    }    task.resume()}