03.12
[此文章僅供ActionSctipt2.0 參考]
在Flash有許多種連接外部資料的方法,例如您可以用以下的方法:
- Text
- XML
- WebServices
- FlashRemoting
- RTMP
當然,在這些方法中,最安全也最方便的,就是FlashRemoting了,而FlashRemoting之所以會比其他方法要來的好的原因,就在於資料傳送可以動態壓縮,資料型態也能自動轉換,這對程式撰寫上有很大的優勢,當然對於資料的安全性(存取遠端服務上的權限也會較為容易控制與管理),那個該如何做呢?
以往在傳統網站中,若是要保持與Session的連線,透過的就是用瀏覽器中的Cookie來記憶Session id,但是在Flash中可沒有這個東西,讓我又要如何透過HTTP表頭來把資料給傳遞出去呢?其實用的就是Service.Connection.setCredentials這個方法,舉個例子來說,若我們要產生連線,則可以將帳號密碼設在setCredentials中來產生新的連線,若是要取消,只要設定空字串就可以了,請看下方的案例:
check_btn.addEventListener("click", checkHandler);
function checkHandler():Void {
//呼叫服務
var pc:PendingCall = myService.checkLogin();
pc.responder = new RelayResponder(_root, "checkDone", "riaFail");
}
login_btn.addEventListener("click", loginHandler);
function loginHandler():Void {
if (account_txt.text != "" && passwd_txt.text != "") {
//真正在做login
myService.connection.setCredentials(account_txt.text, passwd_txt.text);
//順便檢查是否登入成功,並回結果
var pc:PendingCall = myService.login();
pc.responder = new RelayResponder(_root, "loginDone", "riaFail");
} else {
state_txt.text += "請輸入完整的帳號密碼…n";
}
}
logout_btn.addEventListener("click", logoutHandler);
function logoutHandler():Void {
myService.connection.setCredentials("","");
var pc:PendingCall = myService.logout();
pc.responder = new RelayResponder(_root, "loginDone", "riaFail");
}
這就能正確的產生使用者驗證的要求(登入),以及將使用者給登出,如此就能避免駭客直接透過HTTP去攻擊您遠地端的服務,達到系統安全保護上的目的。
相關文章:
文章內容由宋志峰[ANISTAR]撰寫,引用分享請以鏈結形式註明出處與原始作者。


你好~我有問題想請教一下~
我想用Flash透過AMFPHP取得原本存在伺服器端裡SESSION的資料
程式在AMFPHP測試頁取SESION的值是沒問題的~
但當用Flash透過AMFPHP取Session的值的時候卻是NULL
是哪裡有問題了嗎?
如果測試頁可以正確拿到資訊,理論上Flash也可以, 目前我在專案中也是會用seesion, 是能正常取得seesion資訊的.