diff --git a/operateDocsExample1/operateAPIUtilities.swift b/operateDocsExample1/operateAPIUtilities.swift index 0e552c7f6f3161df5414597f37dbc2b80ea592c5..2b88352ae1a03b5fd7744e5efe2a53d9eae98db1 100644 --- a/operateDocsExample1/operateAPIUtilities.swift +++ b/operateDocsExample1/operateAPIUtilities.swift @@ -87,11 +87,15 @@ class operateAPIUtilities { forHTTPHeaderField: "Content-Type") let deleteBody = "itemid=\(id)" request.httpBody = deleteBody.data(using: String.Encoding.utf8) - let req: URLRequest = request as URLRequest - - let task = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in + + // set up the session + let config = URLSessionConfiguration.default + config.httpShouldSetCookies = false + let session = URLSession(configuration: config) + + let task = session.dataTask(with: req, completionHandler: { data, response, error in if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { @@ -113,7 +117,12 @@ class operateAPIUtilities { let req = deleteRequest(endpoint: "note", id: id) - let task = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in + // set up the session + let config = URLSessionConfiguration.default + config.httpShouldSetCookies = false + let session = URLSession(configuration: config) + + let task = session.dataTask(with: req, completionHandler: { data, response, error in if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { @@ -149,7 +158,12 @@ class operateAPIUtilities { let req: URLRequest = request as URLRequest - let task = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in + // set up the session + let config = URLSessionConfiguration.default + config.httpShouldSetCookies = false + let session = URLSession(configuration: config) + + let task = session.dataTask(with: req, completionHandler: { data, response, error in guard error == nil && data != nil else { //handle errors here @@ -200,7 +214,12 @@ class operateAPIUtilities { let req: URLRequest = request as URLRequest - let task = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in + // set up the session + let config = URLSessionConfiguration.default + config.httpShouldSetCookies = false + let session = URLSession(configuration: config) + + let task = session.dataTask(with: req, completionHandler: { data, response, error in guard error == nil && data != nil else { print("error=\(String(describing: error))") @@ -262,11 +281,9 @@ class operateAPIUtilities { // set up the session let config = URLSessionConfiguration.default - config.timeoutIntervalForRequest = 10 config.httpShouldSetCookies = false let session = URLSession(configuration: config) - //let task = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in let task = session.dataTask(with: req, completionHandler: { data, response, error in print("req.allHTTPHeaderFields.debugDescription")