【发布时间】:2017-02-27 16:47:41
【问题描述】:
我一直在尝试使用 Alamofire 的基本身份验证支持:
self.sessionManager.request(request)
.authenticate(user: user,
password: passwordHashAsHex)
但是,我从我的网络服务器收到 403。
如果我自己添加 auth 标头:
let authString = "\(user):\(passwordHashAsHex)"
guard let auth = authString.data(using: String.Encoding.utf8) else {
throw ...
}
request.setValue("Basic \(auth.base64EncodedString())",
forHTTPHeaderField: "Authorization"
)
效果很好。
在 Alamofire 的完成/响应处理程序中检查 response.request!.allHTTPHeaderFields,我注意到没有条目 Authorization。为什么不呢?
【问题讨论】:
标签: swift http-headers alamofire basic-authentication