這裏是我的代碼:Alamofire的Swift 2.0:如何使用X-WSSE授權發送http頭文件?
> 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上的文檔。有些事情我做得不對。
感謝
代碼中的'manager'如何?阿拉莫菲爾的一些包裝? –
呀。經理是Alamofire.Manager.sharedInstance。它是一個包裝。 – Pleirosei