<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableURLRequest",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableURLRequest"
  },
  "title" : "NSMutableURLRequest"
}
-->

# NSMutableURLRequest

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

```
class NSMutableURLRequest
```

## Overview

In Swift, this object bridges to [`NSURLRequest`](/documentation/Foundation/NSURLRequest) and you use when you need reference semantics or other Foundation-specific behavior.

[`NSMutableURLRequest`](/documentation/Foundation/NSMutableURLRequest) is a subclass of [`NSURLRequest`](/documentation/Foundation/NSURLRequest) that allows you to change the request’s properties.

[`NSMutableURLRequest`](/documentation/Foundation/NSMutableURLRequest) only represents information about the request. Use other classes, such as [`URLSession`](/documentation/Foundation/URLSession), to send the request to a server. See [Fetching website data into memory](/documentation/Foundation/fetching-website-data-into-memory) and [Uploading data to a website](/documentation/Foundation/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:)`](/documentation/Foundation/URLSession/dataTask(with:completionHandler:)-e6xv) to create a data task from a request, and then later change the request, the data task continues using the original request.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/URLRequest`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSMutableURLRequest`` class and its immutable superclass, ``doc://com.apple.foundation/documentation/Foundation/NSURLRequest``. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Working with a cache policy

[`cachePolicy`](/documentation/Foundation/NSMutableURLRequest/cachePolicy)

The request’s cache policy.

[`NSURLRequest.CachePolicy`](/documentation/Foundation/NSURLRequest/CachePolicy-swift.enum)

The constants used to specify interaction with the cached responses.

### Accessing request components

[`httpMethod`](/documentation/Foundation/NSMutableURLRequest/httpMethod)

The HTTP request method.

[`url`](/documentation/Foundation/NSMutableURLRequest/url)

The URL being requested.

[`httpBody`](/documentation/Foundation/NSMutableURLRequest/httpBody)

The request body.

[`httpBodyStream`](/documentation/Foundation/NSMutableURLRequest/httpBodyStream)

The request body as an input stream.

[`mainDocumentURL`](/documentation/Foundation/NSMutableURLRequest/mainDocumentURL)

The main document URL.

### Accessing header fields

[`allHTTPHeaderFields`](/documentation/Foundation/NSMutableURLRequest/allHTTPHeaderFields)

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

[`addValue(_:forHTTPHeaderField:)`](/documentation/Foundation/NSMutableURLRequest/addValue(_:forHTTPHeaderField:))

Adds a value to the header field.

[`setValue(_:forHTTPHeaderField:)`](/documentation/Foundation/NSMutableURLRequest/setValue(_:forHTTPHeaderField:))

Sets a value for the header field.

### Controlling request behavior

[`timeoutInterval`](/documentation/Foundation/NSMutableURLRequest/timeoutInterval)

The request’s timeout interval, in seconds.

[`httpShouldHandleCookies`](/documentation/Foundation/NSMutableURLRequest/httpShouldHandleCookies)

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

[`httpShouldUsePipelining`](/documentation/Foundation/NSMutableURLRequest/httpShouldUsePipelining)

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

[`allowsCellularAccess`](/documentation/Foundation/NSMutableURLRequest/allowsCellularAccess)

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

### Supporting limited modes

[`allowsConstrainedNetworkAccess`](/documentation/Foundation/NSMutableURLRequest/allowsConstrainedNetworkAccess)

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

[`allowsExpensiveNetworkAccess`](/documentation/Foundation/NSMutableURLRequest/allowsExpensiveNetworkAccess)

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

### Accessing the service type

[`networkServiceType`](/documentation/Foundation/NSMutableURLRequest/networkServiceType)

The network service type of the connection.

[`NSURLRequest.NetworkServiceType`](/documentation/Foundation/NSURLRequest/NetworkServiceType-swift.enum)

Constants that specify how a request uses network resources.

### Working with hotspots

[`bind(to:)`](/documentation/Foundation/NSMutableURLRequest/bind(to:))

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

### Indicating the source of the request

[`attribution`](/documentation/Foundation/NSMutableURLRequest/attribution)

The entity that initiates the network request.

[`NSURLRequest.Attribution`](/documentation/Foundation/NSURLRequest/Attribution-swift.enum)

The entities that can make a network request.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)