Skip to content

Instantly share code, notes, and snippets.

@puttputt
Created September 11, 2014 23:18
Show Gist options
  • Save puttputt/1ae6e88c77a3ce8f92d2 to your computer and use it in GitHub Desktop.
Save puttputt/1ae6e88c77a3ce8f92d2 to your computer and use it in GitHub Desktop.
http get request swift
var googleUrl = NSURL(string: "http://google.ca")
var request = NSMutableURLRequest(URL: googleUrl)
request.HTTPMethod = "GET"
request.addValue("text/html", forHTTPHeaderField: "Content-Type")
var session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
if((error) != nil) {
println(error.localizedDescription)
}
var strData = NSString(data: data, encoding: NSASCIIStringEncoding)
println(strData)
})
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment