这是我的代码:
> let uuid: CFUUIDRef = CFUUIDCreate(nil)
let nonce: CFStringRef = CFUUIDCreateString(nil, uuid)
let dateFormatter: NSDateFormatter = NSDateFormatter()
let timestamp = NSDate()
let secretKey = "DAqE6lBUgzxJRuR287GR"
let username = "us_demo003"
let formattedDate: String = dateFormatter.stringFromDate(timestamp)
let text = String((nonce as String)+formattedDate+secretKey)
let sha1 = text.sha1()
let passwordDigest = sha1.toBase64()
let headers = ["Username":username,"PasswordDigest": passwordDigest, "Nonce":(nonce as String), "Created":formattedDate]
let theUrlString = "url here"
manager.request(.GET, theUrlString, parameters: nil, encoding: ParameterEncoding.URL, headers: theHeaders).responseJSON { (result) -> Void in
print("BEGIN")
print("\n\n\n\n\n\n\n\nBEGIN\n\(result)\n\n\n\n\n\nEND")
print("STOP")
}
我得到的结果如下:
SUCCESS: {
data = "";
replyCode = 1;
replyText = "No Authentication Header";
}
我如何使用Alamofire发送身份验证标头?我已经检查了github上的文档。我做错了什么。
谢谢
最佳答案
相反,您想创建Authorization
标头,其中Authorization
是字典键,而WWSE profile=\"username_token\"
是值。然后,您还需要将X-WSSE
标头密钥设置为UsernameToken Username="admin", PasswordDigest="buctlzbeVflrVCoEfTKB1mkltCI=", Nonce="ZmMzZDg4YzMzYzRmYjMxNQ==", Created="2014-03-22T15:24:49+00:00"
。
let token = "some generated token"
let headers = [
"Authorization": "WWSE profile=\"\(token)\""
"X-WSSE": "UsernameToken Username=\"admin\", PasswordDigest=\"buctlzbeVflrVCoEfTKB1mkltCI=\", Nonce=\"ZmMzZDg4YzMzYzRmYjMxNQ==\", Created=\"2014-03-22T15:24:49+00:00\""
]
可以在here中找到有关WSSE auth的更多信息。
关于ios - 带有Alamofire的Swift 2.0:如何通过X-WSSE授权发送HTTP header ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34952442/