以下是发出请求的片段。
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
let configurationId = String(format: "NetworkManager%d", UInt16(arc4random_uniform(UInt32(UINT16_MAX))))
let configuration = URLSessionConfiguration.background(withIdentifier: configurationId)
let session = Foundation.URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue.current)
let task = session.downloadTask(with: request)
task.resume()
发出此请求时,不会调用如下所述的身份验证质询方法。
@nonobjc func urlSession(_ session: Foundation.URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: (Foundation.URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
@nonobjc func urlSession(_ session: Foundation.URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: (Foundation.URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)