sendSynchronousRequest(_:returning:)
Performs a synchronous load of the specified URL request.
Declaration
class func sendSynchronousRequest(_ request: URLRequest, returning response: AutoreleasingUnsafeMutablePointer<URLResponse?>?) throws -> DataParameters
- request:
The URL request to load. The
requestobject is deep-copied as part of the initialization process. Changes made torequestafter this method returns do not affect the request that is used for the loading process. - response:
Out parameter for the URL response returned by the server.
Return Value
The downloaded data for the URL request. Returns nil if a connection could not be created or if the download fails.
Discussion
A synchronous load is built on top of the asynchronous loading code made available by the class. The calling thread is blocked while the asynchronous loading system performs the URL load on a thread spawned specifically for this load request. No special threading or run loop configuration is necessary in the calling thread in order to perform a synchronous load.
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.