Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Use this manager class
- class APIManager {
- static var Manager: Alamofire.SessionManager = {
- let manager = ServerTrustPolicyManager(policies: ["autoboutique.me": ServerTrustPolicy.disableEvaluation])
- let session = SessionManager(serverTrustPolicyManager: manager)
- return session
- }()
- }
- extension AppDelegate: URLSessionDelegate {
- public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- //Trust the certificate even if not valid
- let urlCredential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
- completionHandler(.useCredential, urlCredential)
- }
- }
- let json: [String: AnyObject] = parameter
- // ["username": "admin","password": "9yWpe6v7(OZ7"]
- let jsonData = try? JSONSerialization.data(withJSONObject: json)
- let url = URL(string: strUrl)!
- var request = URLRequest(url: url)
- request.httpMethod = httpMethod
- request.setValue("\(jsonData!.count)", forHTTPHeaderField: "Content-Length")
- request.setValue("application/json", forHTTPHeaderField: "Content-Type")
- if !utilitiesClass.isEmpty(SingleTone.shared.strCustomerToken)
- {
- request.setValue("Bearer \(SingleTone.shared.strCustomerToken)", forHTTPHeaderField: "Authorization")
- }
- // Insert json data to the request
- request.httpBody = jsonData
- let session = URLSession(configuration: URLSessionConfiguration.default, delegate: controller, delegateQueue: nil)
- session.dataTask(with: request)
- let task = session.dataTask(with: request) { data, response, error in
- guard let data = data, error == nil else {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement