as3httpclient: オープンソースのHTTP/HTTPS AS3クライアント

Bloglinesの様のAPIを利用するとき、HTTP/GETを基づいてHTTPの認証機能が必要となりますが、Adobe Flash Player 9のURLLoaderクラスはそれがサポートされていません。

as3httpclientとは、該当問題を解決するためActionScript 3のオープンソースのHTTP/HTTPSライブラリクラスです。

as3httpclientは次の特徴があります。

●HTTP/GET経由してHTTPベースの認証をサポートする
●違う方法でHTTPステータスメッセージを取れる
●HTTPSをサポートする

使用例:




import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import com.abdulqabiz.net.HTTPURLLoader;
import com.abdulqabiz.crypto.Base64;
private var loader:HTTPURLLoader;
private var END_POINT:String = “http://rpc.bloglines.com/”;
//you need to set your email/password required for Bloglines access.
private var email:String = “YOUR_EMAIL_FOR_BLOGLINES”;
private var password:String = “YOUR_BLOGLINES_PASSWORD”;
private function onAppInit()
{
loader = new HTTPURLLoader();
loader.addEventListener(“complete”, onComplete);
loader.addEventListener(“httpStatus”, onHTTPStatus);
loader.addEventListener(“progress”, onProgress);
//for simplicity,not handling following three events.
//loader.addEventListener(“close”, onClose);
//loader.addEventListener(“ioError”, onIOError);
//loader.addEventListener(“securityError”,onSecurityError);
}
private function onComplete(event:Event)
{
//headers stroed as name-value(hash map)
var rh:Object = HTTPURLLoader(event.target).responseHeaders;
var str:String = “”;
for(var p:String in rh) str+= p + “:” + rh[p] + “\n”;
console.text+=”Response Headers: \n” + str + “\n\n”;
//data property holds the content
console.text+=”Body Content:\n” + HTTPURLLoader(event.target).data + “\n\n”;
}
private function onProgress(event:ProgressEvent)
{
//bytesTotal is not accurate, and its 0 if server doesn’t send Content-Length header.
console.text+= “Event: progress:-\n” + “bytesLoaded: ” + event.bytesLoaded + “\n\n”;
}
private function onHTTPStatus(event:HTTPStatusEvent)
{
//if httpStatus is 401, 403, 404, 500, 501, socket is closed.
console.text+= “Event: httpStatus (” + event.status + “)\n\n”;
}
private function loadURL()
{
var request:URLRequest = new URLRequest();
//call listsubs method of Bloglines
request.url = END_POINT + “listsubs”;
var credentials:String = Base64.encode(email + “:” + password);
//create HTTP Auth request header
var authHeader:URLRequestHeader = new URLRequestHeader(“Authorization”,”Basic ” + credentials);
//add the header to request
request.requestHeaders.push(authHeader);
//make the request.
loader.load(request);
}




公式サイト:

http://code.google.com/p/as3httpclient/

Leave a Reply

Your email address will not be published. Required fields are marked *