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.

Getting Response Status Code

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software