swift 使用基本HTTP authirization发送请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 使用基本HTTP authirization发送请求相关的知识,希望对你有一定的参考价值。
let username = "username"
let password = "password"
let credentialData = "\(username):\(password)".data(using: String.Encoding.utf8)!
let base64Credentials = credentialData.base64EncodedString(options: [])
let headers = ["Authorization": "Basic \(base64Credentials)"]
let parameters: [String: Any] = ["someKey" : "<my_email>"]
Alamofire.request("url_here",
method: .post,
parameters: parameters,
encoding: URLEncoding.queryString,
headers: headers)
.responseString { response in
print(response)
if response.result.isSuccess {
} else {
}
}
以上是关于swift 使用基本HTTP authirization发送请求的主要内容,如果未能解决你的问题,请参考以下文章