Structure

URLRequest

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

Declaration

struct URLRequest

Overview

URLRequest encapsulates two basic data elements of a load request: the URL to load, and the policy to use when consulting the URL content cache made available by the implementation.

Topics

Creating a Request

init(url: URL, cachePolicy: URLRequest.CachePolicy, timeoutInterval: TimeInterval)

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

Working with a Cache Policy

var cachePolicy: URLRequest.CachePolicy

The request’s cache policy.

typealias URLRequest.CachePolicy

An alias for the 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 of the request.

var httpBody: Data?

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

var httpBodyStream: InputStream?

The stream used to deliver the HTTP body.

var mainDocumentURL: URL?

The main document URL associated with this request.

Accessing Header Fields

var allHTTPHeaderFields: [String : String]?

A dictionary containing all the request’s HTTP header fields.

func addValue(String, forHTTPHeaderField: String)

Adds one value to the header field.

Controlling Request Behavior

var timeoutInterval: TimeInterval

The timeout interval of the request.

var httpShouldHandleCookies: Bool

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

var httpShouldUsePipelining: Bool

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

var allowsCellularAccess: Bool

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

Accessing the Service Type

var networkServiceType: URLRequest.NetworkServiceType

The service type associated with this request.

typealias URLRequest.NetworkServiceType

An alias for the network service type.

enum NSURLRequest.NetworkServiceType

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

Comparing Requests

static func != (URLRequest, URLRequest) -> Bool

Returns a Boolean value indicating whether two values are not equal.

static func == (URLRequest, URLRequest) -> Bool

Indicates whether two URL requests are the same.

Describing Requests

var description: String

A textual description of the request.

var debugDescription: String

A textual description of the request suitable for debugging.

var customMirror: Mirror

A mirror that reflects the request.

var hashValue: Int

The computed hash value for the request.

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.

class NSMutableURLRequest

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

typealias URLRequest.ReferenceType

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

See Also

Requests and Responses

class URLResponse

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

class HTTPURLResponse

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