Created
April 19, 2018 16:58
-
-
Save terrybu/a913c3283f770c10ba0d5afa062cf7f0 to your computer and use it in GitHub Desktop.
NSURLRequest example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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