ใน Swift กับ iOS 9 คุณสามารถทำได้ด้วยวิธีนี้:
if let url = NSURL(string: requestUrl) {
let request = NSMutableURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 300)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if let httpResponse = response as? NSHTTPURLResponse {
print("Status code: (\(httpResponse.statusCode))")
}
})
task.resume()
}