Class

NSMutableURLRequest

A mutable URL load request that bridges to NSURLRequest and you use when you need reference semantics or other Foundation-specific behavior.

Declaration

class NSMutableURLRequest : NSURLRequest

Overview

NSMutableURLRequest is a subclass of NSURLRequest that allows you to change the request’s properties.

NSMutableURLRequest only represents information about the request. Use other classes, such as URLSession, to send the request to a server. See Fetching Website Data into Memory and Uploading Data to a Website for an introduction to these techniques.

Classes that create a network operation based on a request make a deep copy of that request. Thus, changing the request after creating a network operation has no effect on the ongoing operation. For example, if you use dataTask(with:completionHandler:) to create a data task from a request, and then later change the request, the data task continues using the original request.

Topics

Working with a Cache Policy

var cachePolicy: NSURLRequest.CachePolicy

The request’s 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 being requested.

var httpBody: Data?

The request body.

var httpBodyStream: InputStream?

The request body as an input stream.

var mainDocumentURL: URL?

The main document URL.

Accessing Header Fields

var allHTTPHeaderFields: [String : String]?

A dictionary containing all of the HTTP header fields for a request.

func addValue(String, forHTTPHeaderField: String)

Adds a value to the header field.

func setValue(String?, forHTTPHeaderField: String)

Sets a value for the header field.

Controlling Request Behavior

var timeoutInterval: TimeInterval

The request’s timeout interval, in seconds.

var httpShouldHandleCookies: Bool

A Boolean value that indicates whether the request 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.

var allowsCellularAccess: Bool

A Boolean value that indicates whether a connection can use the device’s cellular network (if present).

Accessing the Service Type

var networkServiceType: NSURLRequest.NetworkServiceType

The network service type of the connection.

enum NSURLRequest.NetworkServiceType

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

Working with Hotspots

func bind(to: NEHotspotHelperCommand)

Binds a URL request to the network interface associated with the hotspot helper command instance.

Relationships

Inherits From

Conforms To

See Also

Using Reference Types

class NSURLRequest

A representation of a URL load request that you use when you need reference semantics or other Foundation-specific behavior.

typealias URLRequest.ReferenceType

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

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