0

以下是发出请求的片段。

        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)
4

1 回答 1

0

尝试使用与您在问题中列出的标题略有不同的以下标题。

open func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    //handle challenge here.
}
于 2017-07-05T12:11:39.090 回答