I've been doing some tests connecting to an OAuth service using Postman. Everything works great and I can see the JSON response. However, the code that Postman generates doesn't include any of the tokens.
How would I do this in Swift? I also don't want to use any 3rd party libraries, as I want to learn how to do this.
Here is the code that Postman generates. There is nothing about how to generate the token.
import Foundation
let headers = [
"cache-control": "no-cache",
"postman-token": "31761212-1492-2111-aa2d-da54b8f1983b"
]
let request = NSMutableURLRequest(url: NSURL(string: "https://xxxdev.service-now.com/api/now/table/sc_request")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Thanks