How to make 'post' HTTP request in Swift?

hello! I've a log in page in my app in which I'm doing authentication and making a post request.

I'll be grabbing the token from the API that I'm provided with.

However, my code isn't printing anything on the print log. Please help!!


    @IBAction func submit(sender: AnyObject) {

//creating a function that will connect to API


        func connectToWebAPI(){

//setting up the base64-encoded credentials
        let userName = "user"
        let password = "pass"
        let loginString = NSString(format: "%@:%@", userName, password)
        let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
        let base64LoginString = loginData.base64EncodedStringWithOptions(nil)

//creating the request
        let url = NSURL(string: "http://www.telize.com/geoip") 
        var request = NSMutableURLRequest(URL: url!)
        let config = NSURLSessionConfiguration.defaultSessionConfiguration()
        let session = NSURLSession.sharedSession()
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        request.addValue("application/json", forHTTPHeaderField: "Accept")
    
        let urlConnection = NSURLConnection(request: request, delegate: self)
        request.HTTPMethod = "POST"
        request.setValue(base64LoginString, forHTTPHeaderField: "Authorization")
    
    
        let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
        if (error != nil) {
                    println(error)
            
        }
        else {

// converting the data into Dictionary

        let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
            
        println(jsonResult)
            
                }
            })


//fire off the request
    
        task.resume()

        }

You create an NSMutableURLRequest instance, which is not used in session.dataTaskWithURL .

I'm afraid the line should be:

let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in


Calling dataTaskWithURL will generate a simple GET task for the URL.

How to make 'post' HTTP request in Swift?
 
 
Q