Skip to content

Instantly share code, notes, and snippets.

@nguyentruongky
Created April 4, 2018 21:00
Show Gist options
  • Save nguyentruongky/8adbf7534c4313ddbb71fad64b58184c to your computer and use it in GitHub Desktop.
Save nguyentruongky/8adbf7534c4313ddbb71fad64b58184c to your computer and use it in GitHub Desktop.
let userName = "myUsername"
let password = "myPassword"
let authString = userName + ":" + password
let credentialData = authString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64Credentials = credentialData.base64EncodedStringWithOptions([])
let headers = ["Authorization": "Basic " + base64Credentials]
let url = URL(string: api)!
Alamofire.request(url, method: .post,
parameters: params,
encoding: JSONEncoding.default,
headers: headers)
.validate().responseJSON { (response) in
print(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment