Class

NSURLRequest

NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.

Overview

NSURLRequest encapsulates two basic data elements of a load request: the URL to load, and the policy to use when consulting the URL content cache made available by the implementation.

NSURLRequest is designed to be extended to support additional protocols by adding categories that provide accessor methods for your own protocol-specific properties. Those methods can get and set the actual values by calling the NSURLProtocol methods property(forKey:in:) and setProperty(_:forKey:in:).

The mutable subclass of NSURLRequest is NSMutableURLRequest.

Nested Types

NSURLRequestNetworkServiceType

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

NSURLRequestCachePolicy

These constants are used to specify interaction with the cached responses.

Symbols

Creating Requests

init(url: URL)

Returns a URL request for a specified URL with default cache policy and timeout value.

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

Returns an initialized URL request with specified values.

Getting Request Properties

var cachePolicy: NSURLRequest.CachePolicy

The receiver’s cache policy.

var httpShouldUsePipelining: Bool

A boolean value that indicates whether the request should continue transmitting data before receiving a response from an earlier transmission.

var mainDocumentURL: URL?

The main document URL associated with the request.

var timeoutInterval: TimeInterval

The receiver’s timeout interval, in seconds.

var networkServiceType: NSURLRequest.NetworkServiceType

The network service type of the request.

var url: URL?

The request's URL.

Getting HTTP Request Properties

var allHTTPHeaderFields: [String : String]?

All of the receiver’s HTTP header fields.

var httpBody: Data?

The receiver’s HTTP body data.

var httpBodyStream: InputStream?

The receiver’s HTTP body stream.

var httpMethod: String?

The receiver’s HTTP request method.

var httpShouldHandleCookies: Bool

A boolean value that indicates whether the default cookie handling will be used for this request.

func value(forHTTPHeaderField: String)

Returns the value of the specified HTTP header field.

Allowing Cellular Access

var allowsCellularAccess: Bool

A boolean value that indicates whether the request is allowed to use the cellular radio (if present).

Support for Secure Coding

class var supportsSecureCoding: Bool

Indicates that NSURLRequest implements the NSSecureCoding protocol.

Constants

CachePolicy

These constants are used to specify interaction with the cached responses.

NetworkServiceType

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