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


class HTTPURLResponse : URLResponse


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 response.

func value(forHTTPHeaderField: String) -> String?

Returns the value that corresponds to the given header field.

Getting Response Status Codes

class func localizedString(forStatusCode: Int) -> String

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

var statusCode: Int

The response’s HTTP status code.


Inherits From

Conforms To

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.