Structure

URLRequest

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

Topics

Creating a Request

init(url: URL, cachePolicy: URLRequest.CachePolicy, timeoutInterval: TimeInterval)

Creates and initializes a URL request with the given URL and cache policy.

Working with a Cache Policy

var cachePolicy: URLRequest.CachePolicy

The cache policy of the receiver.

typealias URLRequest.CachePolicy

An alias for the cache policy.

enum NSURLRequest.CachePolicy

The constants used to specify interaction with the cached responses.

Accessing Request Components

var httpMethod: String?

The HTTP request method.

var url: URL?

The URL of the request.

var httpBody: Data?

The data sent as the message body of the request, such as for an HTTP POST request.

var httpBodyStream: InputStream?

The request’s HTTP body stream.

var mainDocumentURL: URL?

The main document URL associated with this request.

Accessing Header Fields

var allHTTPHeaderFields: [String : String]?

A dictionary containing all the HTTP header fields of the receiver.

func addValue(String, forHTTPHeaderField: String)

Adds one value to the header field.

Controlling Request Behavior

var timeoutInterval: TimeInterval

The timeout interval of the request.

var httpShouldHandleCookies: Bool

Indicates whether cookies will be sent with and set for this request.

var httpShouldUsePipelining: Bool

Indicates whether the receiver should transmit before the previous response is received.

var allowsCellularAccess: Bool

Indicates whether the request is allowed to use the built in cellular radios to satisfy the request.

Accessing the Service Type

var networkServiceType: URLRequest.NetworkServiceType

The service type associated with this request.

typealias URLRequest.NetworkServiceType

An alias for the network service type.

enum NSURLRequest.NetworkServiceType

The constants used to specify the network service type of a request.

Comparing Requests

Describing Requests

var description: String

A textual description of the request.

var debugDescription: String

A textual description of the request suitable for debugging.

var customMirror: Mirror

A mirror that reflects the request.

var hashValue: Int

The computed hash value for the request.

Using Reference Types

class NSURLRequest

An object that represents URL load request that bridges to URLRequest; use NSURLRequest when you need reference semantics or other Foundation-specific behavior.

class NSMutableURLRequest

A mutable object that represents a URL load request that bridges to URLRequest; use NSMutableURLRequest when you need reference semantics or other Foundation-specific behavior.

typealias URLRequest.ReferenceType

An alias for this value type's equivalent reference type.

See Also

Requests and Responses

class NSMutableURLRequest

A mutable object that represents a URL load request that bridges to URLRequest; use NSMutableURLRequest when you need reference semantics or other Foundation-specific behavior.

class URLResponse

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

class HTTPURLResponse

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