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.

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.

Topics

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.

Working with a Cache Policy

var cachePolicy: NSURLRequest.CachePolicy

The receiver’s cache policy.

enum NSURLRequest.CachePolicy

The constants used to specify interaction with the cached responses.

Accessing Request Components

var httpMethod: String?

The receiver’s HTTP request method.

var url: URL?

The request's URL.

var httpBody: Data?

The receiver’s HTTP body data.

var httpBodyStream: InputStream?

The receiver’s HTTP body stream.

var mainDocumentURL: URL?

The main document URL associated with the request.

Getting Header Fields

var allHTTPHeaderFields: [String : String]?

All of the receiver’s HTTP header fields.

func value(forHTTPHeaderField: String)

Returns the value of the specified HTTP header field.

Controlling Request Behavior

var timeoutInterval: TimeInterval

The receiver’s timeout interval, in seconds.

var httpShouldHandleCookies: Bool

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

var httpShouldUsePipelining: Bool

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

var allowsCellularAccess: Bool

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

Accessing the Service Type

var networkServiceType: NSURLRequest.NetworkServiceType

The network service type of the request.

enum NSURLRequest.NetworkServiceType

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

Supporting Secure Coding

class var supportsSecureCoding: Bool

Indicates that NSURLRequest implements the NSSecureCoding protocol.

See Also

Using Reference Types

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.