The metadata associated with the response to an HTTP protocol URL load request.


The HTTPURLResponse class is a subclass of URLResponse that provides methods for accessing information specific to HTTP protocol responses. Whenever you make HTTP URL load requests, any response objects you get back from the URLSession, NSURLConnection, or NSURLDownload class are instances of the HTTPURLResponse class.


Initializing a Response Object

init?(url: URL, statusCode: Int, httpVersion: String?, headerFields: [String : String]?)

Initializes an HTTP URL response object with a status code, protocol version, and response headers.

Getting HTTP Response Headers

var allHeaderFields: [AnyHashable : Any]

All HTTP header fields of the receiver.

Getting Response Status Code

class func localizedString(forStatusCode: Int)

Returns a localized string corresponding to a specified HTTP status code.

var statusCode: Int

The receiver’s HTTP status code.


Inherits From

See Also

Requests and Responses

struct URLRequest

A URL load request that is independent of protocol or URL scheme.

class URLResponse

The metadata associated with the response to a URL load request, independent of protocol and URL scheme.