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

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

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

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

使用例:

  1. <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" creationComplete="onAppInit()">
  2. <mx:Script>
  3. import flash.net.URLRequest;
  4. import flash.net.URLRequestHeader;
  5. import com.abdulqabiz.net.HTTPURLLoader;
  6. import com.abdulqabiz.crypto.Base64;
  7. private var loader:HTTPURLLoader;
  8. private var END_POINT:String = "http://rpc.bloglines.com/";
  9. //you need to set your email/password required for Bloglines access.
  10. private var email:String = "YOUR_EMAIL_FOR_BLOGLINES";
  11. private var password:String = "YOUR_BLOGLINES_PASSWORD";
  12. private function onAppInit()
  13. {
  14. loader = new HTTPURLLoader();
  15. loader.addEventListener("complete", onComplete);
  16. loader.addEventListener("httpStatus", onHTTPStatus);
  17. loader.addEventListener("progress", onProgress);
  18. //for simplicity,not handling following three events.
  19. //loader.addEventListener("close", onClose);
  20. //loader.addEventListener("ioError", onIOError);
  21. //loader.addEventListener("securityError",onSecurityError);
  22. }
  23. private function onComplete(event:Event)
  24. {
  25. //headers stroed as name-value(hash map)
  26. var rh:Object = HTTPURLLoader(event.target).responseHeaders;
  27. var str:String = "";
  28. for(var p:String in rh)    str+= p + ":" + rh[p] + "\n";
  29. console.text+="Response Headers: \n" + str + "\n\n";
  30. //data property holds the content
  31. console.text+="Body Content:\n" + HTTPURLLoader(event.target).data + "\n\n";
  32. }
  33. private function onProgress(event:ProgressEvent)
  34. {
  35. //bytesTotal is not accurate, and its 0 if server doesn't send Content-Length header.
  36. console.text+= "Event: progress:-\n" + "bytesLoaded: " + event.bytesLoaded + "\n\n";
  37. }
  38. private function onHTTPStatus(event:HTTPStatusEvent)
  39. {
  40. //if httpStatus is 401, 403, 404, 500, 501, socket is closed.
  41. console.text+= "Event: httpStatus (" + event.status + ")\n\n";
  42. }
  43. private function loadURL()
  44. {
  45. var request:URLRequest = new URLRequest();
  46. //call listsubs method of Bloglines
  47. request.url = END_POINT + "listsubs";
  48. var credentials:String = Base64.encode(email + ":" + password);
  49. //create HTTP Auth request header
  50. var authHeader:URLRequestHeader = new URLRequestHeader("Authorization","Basic " + credentials);
  51. //add the header to request
  52. request.requestHeaders.push(authHeader);
  53. //make the request.
  54. loader.load(request);
  55. }
  56. </mx:Script>
  57. <mx:Button label="Load URL" click="loadURL()"/>
  58. <mx:TextArea id="console" width="100%" height="100%"/>
  59. </mx:Application>

公式サイト:

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

メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Monday, 22nd March 2010 by admin

Tags: , ,
Posted in ActionScript | Comments (0) | 3,285 views

Leave a Reply