'How to display website status code to user?
Im trying to get the status code of a website and display it to the user. My code is :
override func viewDidLoad() {
super.viewDidLoad()
let dataURL = "https://google.com"
let request = URLRequest(url: URL(string: dataURL)!)
URLSession.shared.dataTask(with: request) { [self] (data, response, error) in
let httpResponse = response as? HTTPURLResponse
let responsecode = httpResponse!.statusCode
ServerStausLabel.text = String(responsecode)
}
}
But for some reason it just displays the default text of the label.
Any help would be greatly appreciated!
EDIT: As Donmag said, I set up the task, but I didn't run it(task.resume).
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
