I\'m trying to send a HTTP request with NSURLSession. It works fine, but when the server doesn\'t respond I can\'t find where the HTTP error code is stored. The
Swift 3:
// handle basic connectivity issues here
guard error == nil else {
print("Error: ", error!)
return
}
// handle HTTP errors here
if let httpResponse = response as? HTTPURLResponse {
let statusCode = httpResponse.statusCode
if (statusCode != 200) {
print ("dataTaskWithRequest HTTP status code:", statusCode)
return;
}
}
if let data = data {
// here, everything is probably fine and you should interpret the `data` contents
}