Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import UIKit
  2.  
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5.  
  6. // Do any additional setup after loading the view.
  7. }
  8.  
  9.  
  10. @IBOutlet weak var txtEmail: UITextField!
  11.  
  12. @IBOutlet weak var txtSenha: UITextField!
  13.  
  14.  
  15. @IBAction func bntLogin(_ sender: Any) {
  16.  
  17.  
  18.  
  19. //let user = txtEmail.text
  20. //let password = txtSenha.text
  21. //let credentialData = "(user):(password)".data(using: <#T##String.Encoding#>)
  22. //let base64Credentials = credentialData?.base64EncodedData(options: <#T##Data.Base64EncodingOptions#>)
  23. //let headers = ["Authorization": "Basic (base64Credentials)"]
  24.  
  25.  
  26. //let user = txtEmail.text
  27. //let password = txtSenha.text
  28. /*
  29. var headers: HTTPHeaders = [:]
  30.  
  31. if let authorizationHeader = Request.authorizationHeader(user: user!, password: password!) {
  32. headers[authorizationHeader.key] = authorizationHeader.value
  33. }
  34.  
  35. Alamofire.request("https://www.url.com.br/wp-json/wp/v2/users", headers: headers).responseJSON {
  36.  
  37. response in debugPrint(response)
  38.  
  39. }
  40. */
  41.  
  42. let username = txtEmail.text
  43. let password = txtSenha.text
  44.  
  45. let loginString = String(format: "%@:%@", username!, password!)
  46. let loginData = loginString.data(using: String.Encoding.utf8)!
  47. let base64LoginString = loginData.base64EncodedString()
  48.  
  49. //Cria uma requisição
  50. let url = URL(string: "https://www.url.com.br/wp-json/wp/v2/users")
  51. var request = URLRequest(url:url!)
  52. request.httpMethod = "POST"
  53. request.setValue("Basic (base64LoginString)", forHTTPHeaderField: "Authorization")
  54.  
  55. // executa
  56. let urlConnection = NSURLConnection(request: request, delegate: self)
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. override func didReceiveMemoryWarning() {
  68. super.didReceiveMemoryWarning()
  69. // Dispose of any resources that can be recreated.
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement