Advertisement
srk72

Bypass ssl api check

May 17th, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. //Use this manager class
  2. class APIManager {
  3. static var Manager: Alamofire.SessionManager = {
  4. let manager = ServerTrustPolicyManager(policies: ["autoboutique.me": ServerTrustPolicy.disableEvaluation])
  5. let session = SessionManager(serverTrustPolicyManager: manager)
  6. return session
  7. }()
  8. }
  9.  
  10. extension AppDelegate: URLSessionDelegate {
  11. public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  12. //Trust the certificate even if not valid
  13. let urlCredential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
  14.  
  15. completionHandler(.useCredential, urlCredential)
  16. }
  17. }
  18.  
  19.  
  20. let json: [String: AnyObject] = parameter
  21. // ["username": "admin","password": "9yWpe6v7(OZ7"]
  22.  
  23. let jsonData = try? JSONSerialization.data(withJSONObject: json)
  24.  
  25.  
  26. let url = URL(string: strUrl)!
  27. var request = URLRequest(url: url)
  28. request.httpMethod = httpMethod
  29. request.setValue("\(jsonData!.count)", forHTTPHeaderField: "Content-Length")
  30. request.setValue("application/json", forHTTPHeaderField: "Content-Type")
  31.  
  32.  
  33. if !utilitiesClass.isEmpty(SingleTone.shared.strCustomerToken)
  34. {
  35. request.setValue("Bearer \(SingleTone.shared.strCustomerToken)", forHTTPHeaderField: "Authorization")
  36. }
  37. // Insert json data to the request
  38. request.httpBody = jsonData
  39.  
  40. let session = URLSession(configuration: URLSessionConfiguration.default, delegate: controller, delegateQueue: nil)
  41.  
  42. session.dataTask(with: request)
  43.  
  44. let task = session.dataTask(with: request) { data, response, error in
  45. guard let data = data, error == nil else {
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement