httpMethod
TypeScriptget httpMethod(): (string) | nullSwift declarationvar httpMethod: String? { get set }The HTTP request method. The default HTTP method is "GET".
struct · iOS 8.0+ · SDK 27.1
struct URLRequestA URL load request that is independent of protocol or URL scheme. ``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`` includes the HTTP method (`GET`, `POST`, and so on) and the HTTP headers. ``URLRequest`` only represents information about the request. Use other classes, such as ``URLSession``, to send the request to a server. See <doc:fetching-website-data-into-memory> and <doc:uploading-data-to-a-website> for an introduction to these techniques. When writing Swift code, favor this structure over the ``NSURLRequest`` and ``NSMutableURLRequest`` classes. Certain header fields are reserved; see <doc:NSURLRequest#Reserved-HTTP-headers>.
get httpMethod(): (string) | nullSwift declarationvar httpMethod: String? { get set }The HTTP request method. The default HTTP method is "GET".
set httpMethod(value: (string) | null)Swift declarationvar httpMethod: String? { get set }The HTTP request method. The default HTTP method is "GET".
get attribution(): NSURLRequest_AttributionSwift declarationvar attribution: URLRequest.Attribution { get set }The entity that initiates the network request. If you don't set this value, the system assumes a value of `NSURLRequest.Attribution.developer`. Use this default value for any network request that your app makes that isn't explicitly from the user. This includes requests that you make to your own server, even when you load user data. It also includes links that the user selects, but that you modify in any way --- including by adding HTTP headers --- before loading the content. Set this value to `NSURLRequest.Attribution.user` only for requests that the user explicitly makes, like when the user enters a URL or taps or clicks a URL that they can read, and only if your app loads and displays the data without altering the request.
set attribution(value: NSURLRequest_Attribution)Swift declarationvar attribution: URLRequest.Attribution { get set }The entity that initiates the network request. If you don't set this value, the system assumes a value of `NSURLRequest.Attribution.developer`. Use this default value for any network request that your app makes that isn't explicitly from the user. This includes requests that you make to your own server, even when you load user data. It also includes links that the user selects, but that you modify in any way --- including by adding HTTP headers --- before loading the content. Set this value to `NSURLRequest.Attribution.user` only for requests that the user explicitly makes, like when the user enters a URL or taps or clicks a URL that they can read, and only if your app loads and displays the data without altering the request.
get cachePolicy(): NSURLRequest_CachePolicySwift declarationvar cachePolicy: URLRequest.CachePolicy { get set }The request's cache policy.
set cachePolicy(value: NSURLRequest_CachePolicy)Swift declarationvar cachePolicy: URLRequest.CachePolicy { get set }The request's cache policy.
get description(): stringSwift declarationvar description: String { get }A textual representation of this instance. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(describing:)` initializer. This initializer works with any type, and uses the custom `description` property for types that conform to `CustomStringConvertible`: struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `description` property.
get customMirror(): SDKHandleSwift declarationvar customMirror: Mirror { get }The custom mirror for this instance. If this type has value semantics, the mirror should be unaffected by subsequent mutations of the instance.
get httpBodyStream(): (InputStream) | nullSwift declarationvar httpBodyStream: InputStream? { get set }The stream used to deliver the HTTP body. The stream is returned for examination only; it's unsafe for the caller to manipulate the stream in any way. > Note: The ``httpBodyStream`` and ``httpBody`` are mutually exclusive --- > only one can be set on a given request. The body stream is preserved > across copies, but is lost when the request is coded via the `NSCoding` > protocol.
set httpBodyStream(value: (InputStream) | null)Swift declarationvar httpBodyStream: InputStream? { get set }The stream used to deliver the HTTP body. The stream is returned for examination only; it's unsafe for the caller to manipulate the stream in any way. > Note: The ``httpBodyStream`` and ``httpBody`` are mutually exclusive --- > only one can be set on a given request. The body stream is preserved > across copies, but is lost when the request is coded via the `NSCoding` > protocol.
get mainDocumentURL(): (string) | nullSwift declarationvar mainDocumentURL: URL? { get set }The main document URL associated with this request. This URL is used for the cookie "same domain as main document" policy.
set mainDocumentURL(value: (string) | null)Swift declarationvar mainDocumentURL: URL? { get set }The main document URL associated with this request. This URL is used for the cookie "same domain as main document" policy.
get timeoutInterval(): numberSwift declarationvar timeoutInterval: TimeInterval { get set }The timeout interval of the request. If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds. As a general rule, you should not use short timeout intervals. Instead, you should provide an easy way for the user to cancel a long-running operation.
set timeoutInterval(value: number)Swift declarationvar timeoutInterval: TimeInterval { get set }The timeout interval of the request. If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds. As a general rule, you should not use short timeout intervals. Instead, you should provide an easy way for the user to cancel a long-running operation.
get debugDescription(): stringSwift declarationvar debugDescription: String { get }A textual representation of this instance, suitable for debugging. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(reflecting:)` initializer. This initializer works with any type, and uses the custom `debugDescription` property for types that conform to `CustomDebugStringConvertible`: struct Point: CustomDebugStringConvertible { let x: Int, y: Int var debugDescription: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(reflecting: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `debugDescription` property.
get networkServiceType(): NSURLRequest_NetworkServiceTypeSwift declarationvar networkServiceType: URLRequest.NetworkServiceType { get set }The type of network service for all tasks within network sessions to enable Cellular Network Slicing. There are two steps to enable Cellular Network Slicing: - Set the entitlements in your property list for `com.apple.developer.networking.slicing.appcategory` and `com.apple.developer.networking.slicing.trafficcategory`. If you don't entitle your app by specifying both these entitlements, your app's network connections won't be using Cellular Network Slicing, even if supported by the carrier. - At the time of network flow creation, set this to the appropriate `NSURLRequest.NetworkServiceType` for your application type.
set networkServiceType(value: NSURLRequest_NetworkServiceType)Swift declarationvar networkServiceType: URLRequest.NetworkServiceType { get set }The type of network service for all tasks within network sessions to enable Cellular Network Slicing. There are two steps to enable Cellular Network Slicing: - Set the entitlements in your property list for `com.apple.developer.networking.slicing.appcategory` and `com.apple.developer.networking.slicing.trafficcategory`. If you don't entitle your app by specifying both these entitlements, your app's network connections won't be using Cellular Network Slicing, even if supported by the carrier. - At the time of network flow creation, set this to the appropriate `NSURLRequest.NetworkServiceType` for your application type.
get allHTTPHeaderFields(): (Record<string, string>) | nullSwift declarationvar allHTTPHeaderFields: [String : String]? { get set }A dictionary containing all of the HTTP header fields for a request. Note that, in keeping with the HTTP RFC, HTTP header field names are case-insensitive.
set allHTTPHeaderFields(value: (Record<string, string>) | null)Swift declarationvar allHTTPHeaderFields: [String : String]? { get set }A dictionary containing all of the HTTP header fields for a request. Note that, in keeping with the HTTP RFC, HTTP header field names are case-insensitive.
get allowsPersistentDNS(): booleanSwift declarationvar allowsPersistentDNS: Bool { get set }`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.
set allowsPersistentDNS(value: boolean)Swift declarationvar allowsPersistentDNS: Bool { get set }`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.
get assumesHTTP3Capable(): booleanSwift declarationvar assumesHTTP3Capable: Bool { get set }`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.
set assumesHTTP3Capable(value: boolean)Swift declarationvar assumesHTTP3Capable: Bool { get set }`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.
get allowsCellularAccess(): booleanSwift declarationvar allowsCellularAccess: Bool { get set }A Boolean value indicating whether the request is allowed to use the built-in cellular radios to satisfy the request. Setting this property to `true` makes the request eligible to run over cellular, subject to other considerations (including, but not limited to, the `URLSessionConfiguration`'s `allowsCellularAccess` property). Setting this value to `false` ensures that the request will never run over cellular.
set allowsCellularAccess(value: boolean)Swift declarationvar allowsCellularAccess: Bool { get set }A Boolean value indicating whether the request is allowed to use the built-in cellular radios to satisfy the request. Setting this property to `true` makes the request eligible to run over cellular, subject to other considerations (including, but not limited to, the `URLSessionConfiguration`'s `allowsCellularAccess` property). Setting this value to `false` ensures that the request will never run over cellular.
get httpShouldHandleCookies(): booleanSwift declarationvar httpShouldHandleCookies: Bool { get set }A Boolean value indicating whether cookies will be sent with and set for this request. `true` if the default cookie handling will be used for this request, `false` otherwise. The default is `true`.
set httpShouldHandleCookies(value: boolean)Swift declarationvar httpShouldHandleCookies: Bool { get set }A Boolean value indicating whether cookies will be sent with and set for this request. `true` if the default cookie handling will be used for this request, `false` otherwise. The default is `true`.
get httpShouldUsePipelining(): booleanSwift declarationvar httpShouldUsePipelining: Bool { get set }A Boolean value indicating whether the request should transmit before the previous response is received.
set httpShouldUsePipelining(value: boolean)Swift declarationvar httpShouldUsePipelining: Bool { get set }A Boolean value indicating whether the request should transmit before the previous response is received.
get requiresDNSSECValidation(): booleanSwift declarationvar requiresDNSSECValidation: Bool { get set }`true` if the request is required to do DNSSEC validation during DNS lookup. `false` otherwise. Defaults to `false`.
set requiresDNSSECValidation(value: boolean)Swift declarationvar requiresDNSSECValidation: Bool { get set }`true` if the request is required to do DNSSEC validation during DNS lookup. `false` otherwise. Defaults to `false`.
get cookiePartitionIdentifier(): (string) | nullSwift declarationvar cookiePartitionIdentifier: String? { get set }set cookiePartitionIdentifier(value: (string) | null)Swift declarationvar cookiePartitionIdentifier: String? { get set }get allowsExpensiveNetworkAccess(): booleanSwift declarationvar allowsExpensiveNetworkAccess: Bool { get set }A Boolean value that indicates whether connections may use a network interface that the system considers expensive. The system determines what constitutes "expensive" based on the nature of the network interface and other factors. iOS 13 considers most cellular networks and personal hotspots expensive. If there are no nonexpensive network interfaces available and the request's `allowsExpensiveNetworkAccess` property is `false`, any task created from the request fails. In this case, the error provided when the task fails has a `URLError.networkUnavailableReason` property whose value is `NSURLErrorNetworkUnavailableReason.NSURLErrorNetworkUnavailableReasonExpensive`. Setting this property on a request overrides the `URLSessionConfiguration.allowsExpensiveNetworkAccess` property of `URLSessionConfiguration`. Limit your app's use of expensive network access to user-initiated tasks, and put off discretionary tasks until a nonexpensive interface becomes available.
set allowsExpensiveNetworkAccess(value: boolean)Swift declarationvar allowsExpensiveNetworkAccess: Bool { get set }A Boolean value that indicates whether connections may use a network interface that the system considers expensive. The system determines what constitutes "expensive" based on the nature of the network interface and other factors. iOS 13 considers most cellular networks and personal hotspots expensive. If there are no nonexpensive network interfaces available and the request's `allowsExpensiveNetworkAccess` property is `false`, any task created from the request fails. In this case, the error provided when the task fails has a `URLError.networkUnavailableReason` property whose value is `NSURLErrorNetworkUnavailableReason.NSURLErrorNetworkUnavailableReasonExpensive`. Setting this property on a request overrides the `URLSessionConfiguration.allowsExpensiveNetworkAccess` property of `URLSessionConfiguration`. Limit your app's use of expensive network access to user-initiated tasks, and put off discretionary tasks until a nonexpensive interface becomes available.
get allowsConstrainedNetworkAccess(): booleanSwift declarationvar allowsConstrainedNetworkAccess: Bool { get set }A Boolean value that indicates whether the request may use the network when the user has specified Low Data Mode. In iOS 13 and later, users can set their device to use Low Data Mode as one of the Cellular Data Options in the Settings app. Users can turn on Low Data Mode to reduce your app's network data usage. This property controls the request's behavior when the user turns on Low Data Mode. If there are no nonconstrained network interfaces available and the request's `allowsConstrainedNetworkAccess` property is `false`, any connection created from the request fails. In this case, the error provided when the connection fails has a `URLError.networkUnavailableReason` property whose value is `NSURLErrorNetworkUnavailableReason.NSURLErrorNetworkUnavailableReasonConstrained`. Setting this property on a request overrides the `URLSessionConfiguration.allowsConstrainedNetworkAccess` property of `URLSessionConfiguration`. Limit your app's use of constrained network access to user-initiated tasks, and put off discretionary tasks until a nonconstrained interface becomes available.
set allowsConstrainedNetworkAccess(value: boolean)Swift declarationvar allowsConstrainedNetworkAccess: Bool { get set }A Boolean value that indicates whether the request may use the network when the user has specified Low Data Mode. In iOS 13 and later, users can set their device to use Low Data Mode as one of the Cellular Data Options in the Settings app. Users can turn on Low Data Mode to reduce your app's network data usage. This property controls the request's behavior when the user turns on Low Data Mode. If there are no nonconstrained network interfaces available and the request's `allowsConstrainedNetworkAccess` property is `false`, any connection created from the request fails. In this case, the error provided when the connection fails has a `URLError.networkUnavailableReason` property whose value is `NSURLErrorNetworkUnavailableReason.NSURLErrorNetworkUnavailableReasonConstrained`. Setting this property on a request overrides the `URLSessionConfiguration.allowsConstrainedNetworkAccess` property of `URLSessionConfiguration`. Limit your app's use of constrained network access to user-initiated tasks, and put off discretionary tasks until a nonconstrained interface becomes available.
get allowsUltraConstrainedNetworkAccess(): booleanSwift declarationvar allowsUltraConstrainedNetworkAccess: Bool { get set }`true` if the receiver is allowed to use an interface marked as ultra-constrained to satify the request, `false` otherwise.
set allowsUltraConstrainedNetworkAccess(value: boolean)Swift declarationvar allowsUltraConstrainedNetworkAccess: Bool { get set }`true` if the receiver is allowed to use an interface marked as ultra-constrained to satify the request, `false` otherwise.
static init(url: string, cachePolicy?: NSURLRequest_CachePolicy, timeoutInterval?: number): URLRequestSwift declarationinit(url: URL, cachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy, timeoutInterval: TimeInterval = 60.0)Creates and initializes a URL request with the given URL, cache policy, and timeout interval. - Parameters: - url: The URL for the request. - cachePolicy: The cache policy for the request. The default is `NSURLRequest.CachePolicy.useProtocolCachePolicy`. - timeoutInterval: The timeout interval for the request. The default is `60.0`. See the commentary for the ``timeoutInterval`` for more information on timeout intervals.
get url(): (string) | nullSwift declarationvar url: URL? { get set }The URL of the request.
set url(value: (string) | null)Swift declarationvar url: URL? { get set }The URL of the request.
value(field: string): (string) | nullSwift declarationfunc value(forHTTPHeaderField field: String) -> String?Retrieves a header value. Note that, in keeping with the HTTP RFC, HTTP header field names are case-insensitive. - Parameter field: The header field name to use for the lookup (case-insensitive). - Returns: The value associated with the header field field, or `nil` if there is no corresponding header field.
addValue(value: string, field: string): voidSwift declarationmutating func addValue(_ value: String, forHTTPHeaderField field: String)Adds a value to the header field. This method provides the ability to add values to header fields incrementally. If a value was previously set for the specified field, the supplied value is appended to the existing value using the appropriate field delimiter (a comma). Certain header fields are reserved. Do not use this method to change such headers. - Parameters: - value: The value for the header field. - field: The name of the header field. In keeping with the HTTP RFC, HTTP header field names are case insensitive.
get httpBody(): (ArrayBuffer) | nullSwift declarationvar httpBody: Data? { get set }The data sent as the message body of a request, such as for an HTTP POST request.
set httpBody(value: (ArrayBuffer) | null)Swift declarationvar httpBody: Data? { get set }The data sent as the message body of a request, such as for an HTTP POST request.
setValue(value: (string) | null, field: string): voidSwift declarationmutating func setValue(_ value: String?, forHTTPHeaderField field: String)Sets a value for the header field. Certain header fields are reserved. Do not use this method to set such headers. Specifically, there is no need for you to set the `Content-Length` header. - Parameters: - value: The new value for the header field. Any existing value for the field is replaced by the new value. - field: The name of the header field to set. In keeping with the HTTP RFC, HTTP header field names are case insensitive.
No declarations were skipped in this snapshot.