Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Last active September 14, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/18763d140d9bcbe3411a960d856bcfb1 to your computer and use it in GitHub Desktop.
Save seanbehan/18763d140d9bcbe3411a960d856bcfb1 to your computer and use it in GitHub Desktop.
basic auth with alamofire in swift
import Alamofire
let url = "https://example.com/"
let user = "me"
let pass = "pwd"
let headers: HTTPHeaders = [
"Authorization": "Basic " + ("\(user):\(pass)".data(using:.utf8)?.base64EncodedString() ?? ""),
]
Alamofire.request(url, headers: headers).responseJSON { response in
debugPrint(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment