【发布时间】:2017-08-20 06:35:52
【问题描述】:
我正在尝试发出此请求,但只返回错误 401,请求是否正确?我必须使用基本身份验证
var user = ""
var password = ""
user = textField.text!
password = textField2.text!
print(user)
print(password)
let credentialData = ("\(user):\(password)").data(using: String.Encoding.utf8)!
print(credentialData)
let base64Credentials = credentialData.base64EncodedString(options: [])
print(base64Credentials)
let headers: HTTPHeaders = ["Authorization":" Basic \(base64Credentials)"]
print(headers)
Alamofire.request("https://www.floratilemevidencia.com.br/wp-json/wp/v2/users/me", headers: headers)
.validate().responseJSON { response in
switch response.result {
case .success:
print("Validation Successful")
let viewController: UIViewController = self.storyboard!.instantiateViewController(withIdentifier: "SideNavigationController")
self.present(viewController, animated: true, completion: { _ in })
case .failure(let error):
print(error.localizedDescription)
self.alertLabel.isHidden = false
}
}
它只返回错误 401。
它是 HTTPHeaders 的正确部分吗?
【问题讨论】:
-
你找到答案了吗?
标签: ios swift3 request alamofire basic-authentication