Skip to content

Instantly share code, notes, and snippets.

@terrybu
Created April 19, 2018 16:58
Show Gist options
  • Save terrybu/a913c3283f770c10ba0d5afa062cf7f0 to your computer and use it in GitHub Desktop.
Save terrybu/a913c3283f770c10ba0d5afa062cf7f0 to your computer and use it in GitHub Desktop.
NSURLRequest example
let todoEndpoint: String = "https://api.instagram.com/oauth/authorize/?client_id=0cf37b02d4404a58addf08b680bc20e2&redirect_uri=https://www.terrybu.com&response_type=code"
guard let url = NSURL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(url: url as URL)
// set up the session
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
// make the request
let task = session.dataTask(with: urlRequest as URLRequest, completionHandler: { (data, response, error) in
// do stuff with response, data & error here
if error == nil {
let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("*****This is the data 4: \(dataString)")
} else {
print(error?.localizedDescription)
}
})
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment