Class

NSMutableURLRequest

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

Declaration

@interface 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 NSURLSession, 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 dataTaskWithRequest: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

cachePolicy

The request’s cache policy.

NSURLRequestCachePolicy

The constants used to specify interaction with the cached responses.

Accessing Request Components

HTTPMethod

The HTTP request method.

URL

The URL being requested.

HTTPBody

The request body.

HTTPBodyStream

The request body as an input stream.

mainDocumentURL

The main document URL.

Accessing Header Fields

allHTTPHeaderFields

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

- addValue:forHTTPHeaderField:

Adds a value to the header field.

- setValue:forHTTPHeaderField:

Sets a value for the header field.

Controlling Request Behavior

timeoutInterval

The request’s timeout interval, in seconds.

HTTPShouldHandleCookies

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

HTTPShouldUsePipelining

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

allowsCellularAccess

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

Supporting Limited Modes

allowsConstrainedNetworkAccess

A Boolean value that indicates whether connections may use the network when the user has specified Low Data Mode.

allowsExpensiveNetworkAccess

A Boolean value that indicates whether connections may use a network interface that the system considers expensive.

Accessing the Service Type

networkServiceType

The network service type of the connection.

NSURLRequestNetworkServiceType

Constants that specify how a request uses network resources.

Working with Hotspots

- bindToHotspotHelperCommand:

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

Relationships

Inherits From

See Also

Requests and Responses

NSURLRequest

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

NSURLResponse

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

NSHTTPURLResponse

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