         
         
         let configuration = URLSessionConfiguration.default
-//        configuration.urlCache = URLCache.sharedURLCacheForRequests()
         let session = URLSession(configuration: configuration, delegate: delegate, delegateQueue: OperationQueue())
         let task = session.dataTask(with: request)
+        
+        let myTask = WTURLSessionTask(task: task)
+        WTURLSessionDelegate.sharedInstance[task] = myTask
         return task
     }
     

    
}

/*
    提供凭据
 */
public class WTURLSessionDelegate:NSObject,URLSessionDataDelegate{
    
    
    private static let sharedInstance = WTURLSessionDelegate()
    
    //网址凭据
    var credential: URLCredential?

    lazy var data:Data = Data()
    var dataTask: URLSessionDataTask?
    var error: NSError?

    
    private func finish(){
        OperationQueue.main {
            self.completionHandler?(self.data,self.response,self.error)
        }
    }
    
    
    private var taskDelegates: [Int: WTURLSessionTask] = [:]
    private let delegateQueue = OperationQueue()
    public subscript(task: URLSessionTask) -> WTURLSessionTask? {
        get{
            var result:WTURLSessionTask?
            let operation = BlockOperation {[unowned self] in
                result = self.taskDelegates[task.taskIdentifier]
            }
            delegateQueue.addOperations([operation], waitUntilFinished: true)
            return result
        }
        set{
            taskDelegates[task.taskIdentifier] = newValue
        }
    }
    
