<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLRequest",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation10URLRequestV"
  },
  "title" : "URLRequest"
}
-->

# URLRequest

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

```
struct URLRequest
```

## Overview

[`URLRequest`](/documentation/Foundation/URLRequest) encapsulates two essential properties of a load request: the URL to load and the policies used to load it. In addition, for HTTP and HTTPS requests, [`URLRequest`](/documentation/Foundation/URLRequest) includes the HTTP method (`GET`, `POST`, and so on) and the HTTP headers.

[`URLRequest`](/documentation/Foundation/URLRequest) 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.

When writing Swift code, favor this structure over the [`NSURLRequest`](/documentation/Foundation/NSURLRequest) and [`NSMutableURLRequest`](/documentation/Foundation/NSMutableURLRequest) classes.

Certain header fields are reserved; see [`Reserved HTTP headers`](/documentation/Foundation/NSURLRequest#Reserved-HTTP-headers).

## Topics

### Creating a request

[`init(url:cachePolicy:timeoutInterval:)`](/documentation/Foundation/URLRequest/init(url:cachePolicy:timeoutInterval:))

Creates and initializes a URL request with the given URL, cache policy, and timeout interval.

### Working with a cache policy

[`cachePolicy`](/documentation/Foundation/URLRequest/cachePolicy-swift.property)

The request’s cache policy.

[`URLRequest.CachePolicy`](/documentation/Foundation/URLRequest/CachePolicy-swift.typealias)

An alias for the 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/URLRequest/httpMethod)

The HTTP request method.

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

The URL of the request.

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

The data sent as the message body of a request, such as for an HTTP POST request.

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

The stream used to deliver the HTTP body.

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

The main document URL associated with this request.

### Accessing header fields

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

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

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

Adds a value to the header field.

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

Sets a value for the header field.

[`value(forHTTPHeaderField:)`](/documentation/Foundation/URLRequest/value(forHTTPHeaderField:))

Retrieves a header value.

### Controlling request behavior

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

The timeout interval of the request.

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

A Boolean value indicating whether cookies will be sent with and set for this request.

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

A Boolean value indicating whether the request should transmit before the previous response is received.

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

A Boolean value indicating whether the request is allowed to use the built-in cellular radios to satisfy the request.

[`allowsPersistentDNS`](/documentation/Foundation/URLRequest/allowsPersistentDNS)

`true` if the request is allowed to store and use DNS answers, potentially beyond TTL expiry, in a persistent
per-process cache, `false` otherwise. Defaults to `false`. This should only be set to
`true` for hostnames whose resolutions are not expected to change across networks.

[`assumesHTTP3Capable`](/documentation/Foundation/URLRequest/assumesHTTP3Capable)

`true` if server endpoint is known to support HTTP/3. Enables QUIC racing
without HTTP/3 service discovery. Defaults to `false`.
The default may be `true` in a future OS update.

[`cookiePartitionIdentifier`](/documentation/Foundation/URLRequest/cookiePartitionIdentifier)

[`requiresDNSSECValidation`](/documentation/Foundation/URLRequest/requiresDNSSECValidation)

`true` if the request is required to do DNSSEC validation during DNS lookup.
`false` otherwise. Defaults to `false`.

### Supporting limited modes

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

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

[`allowsExpensiveNetworkAccess`](/documentation/Foundation/URLRequest/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/URLRequest/networkServiceType-swift.property)

The type of network service for all tasks within network sessions to enable Cellular Network Slicing.

[`URLRequest.NetworkServiceType`](/documentation/Foundation/URLRequest/NetworkServiceType-swift.typealias)

An alias for the network service type.

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

Constants that specify how a request uses network resources.

### Indicating the source of the request

[`attribution`](/documentation/Foundation/URLRequest/attribution-swift.property)

The entity that initiates the network request.

[`URLRequest.Attribution`](/documentation/Foundation/URLRequest/Attribution-swift.typealias)

A type that indicates the entities that can make a network request.

### Using reference types

[`NSURLRequest`](/documentation/Foundation/NSURLRequest)

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

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

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

[`MutableURLRequest`](/documentation/Foundation/MutableURLRequest)



---

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)