Class

NSMutableURLRequest

NSMutableURLRequest is a subclass of NSURLRequest provided to aid developers who may find it more convenient to mutate a single request object for a series of URL load requests instead of creating an immutable NSURLRequest object for each load.

Overview

NSMutableURLRequest, like 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 NSURLSession, NSURLConnection, and NSURLDownload classes make a deep copy of each NSMutableURLRequest object passed to their initializers and task creation methods.

Reserved HTTP Headers

The URL Loading System is designed to handle various aspects of the HTTP protocol for you. As a result, you should not modify the following headers using the addValue(_:forHTTPHeaderField:) or setValue(_:forHTTPHeaderField:) methods:

  • Authorization

  • Connection

  • Host

  • Proxy-Authenticate

  • Proxy-Authorization

  • WWW-Authenticate

Symbols

Setting Request Properties

var cachePolicy: NSURLRequest.CachePolicy

The cache policy of the receiver.

var mainDocumentURL: URL?

The main document URL for the receiver.

var networkServiceType: NSURLRequest.NetworkServiceType

The network service type of the connection.

var timeoutInterval: TimeInterval

The receiver’s timeout interval, in seconds.

var url: URL?

The URL of the receiver

var allowsCellularAccess: Bool

A Boolean value that indicates whether the connection can use the device’s cellular radio (if present). true by default

Setting HTTP Specific Properties

func addValue(String, forHTTPHeaderField: String)

Adds an HTTP header to the receiver’s HTTP header dictionary.

var allHTTPHeaderFields: [String : String]?

The receiver's header fields.

var httpBody: Data?

The request body of the receiver.

var httpBodyStream: InputStream?

The request body as an input stream.

var httpMethod: String

The receiver’s HTTP request method.

var httpShouldHandleCookies: Bool

A boolean value that indicates whether the receiver should use the default cookie handling for the request.

var httpShouldUsePipelining: Bool

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

func setValue(String?, forHTTPHeaderField: String)

Sets the specified HTTP header field.

Relationships

Inherits From

Conforms To