Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. HTTP.globalRequest { req in
  2. req.timeoutInterval = 5
  3. }
  4.  
  5. //set a global SSL pinning setting
  6. HTTP.globalSecurity(HTTPSecurity()) //see the SSL section for more info
  7.  
  8. //set global auth handler. See the Auth section for more info
  9. HTTP.globalAuth { challenge in
  10. return URLCredential(user: "user", password: "passwd", persistence: .forSession)
  11. }
  12.  
  13.  
  14. do {
  15. let opt = try HTTP.GET("https://10.0.1.2:4711/fhem/?cmd=jsonlist2&XHR=1",requestSerializer: JSONParameterSerializer())
  16. //the auth closures will continually be called until a successful auth or rejection
  17. var attempted = false
  18.  
  19. opt.auth = { challenge in
  20. if !attempted {
  21. attempted = true
  22. return URLCredential(forTrust: challenge.proposedCredential?.certificates)
  23. }
  24. return nil
  25. }
  26.  
  27. opt.start { response in
  28.  
  29. print("success")
  30. print("opt finished: (response.data)")
  31. }
  32. } catch let error {
  33. print("got an error creating the request: (error)")
  34. }
  35.  
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement