<!--
{
  "availability" : [
    "iOS: 5.0.0 - 9.0.0",
    "iPadOS: 5.0.0 - 9.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.7.0 - 10.11.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLConnection/sendAsynchronousRequest(_:queue:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLConnection(cm)sendAsynchronousRequest:queue:completionHandler:"
  },
  "title" : "sendAsynchronousRequest(_:queue:completionHandler:)"
}
-->

# sendAsynchronousRequest(_:queue:completionHandler:)

Loads the data for a URL request and executes a handler block on an operation queue when the request completes or fails.

```
class func sendAsynchronousRequest(_ request: URLRequest, queue: OperationQueue, completionHandler handler: @escaping @Sendable (URLResponse?, Data?, (any Error)?) -> Void)
```

## Parameters

`request`

The URL request to load. The `request` object is deep-copied as part of the initialization process. Changes made to `request` after this method returns do not affect the request that is used for the loading process.

`queue`

The operation queue to which the handler block is dispatched when the request completes or failed.

`handler`

The handler block to execute.

## Discussion

If the request completes successfully, the `data` parameter of the handler block contains the resource data, and the `error` parameter is `nil`.  If the request fails, the `data` parameter is `nil` and the error parameter contain information about the failure.

If authentication is required in order to download the request, the required credentials must be specified as part of the URL. If authentication fails, or credentials are missing, the connection will attempt to continue without credentials. If the request finishes with a `401 Unauthorized` status code, the `response` parameter is `nil`, the `data` parameter contains the resource data, and the `error` parameter is an `NSError` with the [`NSURLErrorUserCancelledAuthentication`](/documentation/Foundation/NSURLErrorUserCancelledAuthentication-swift.var) code in the [`NSURLErrorDomain`](/documentation/Foundation/NSURLErrorDomain) error domain.

---

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)