Flex (FLex Builder 3.0) は初めてで、基本的に HTTPS 経由で Freshbooks API (www.freshbooks.com) に対して認証する単純なアプリケーションを作成しています。他に何も送信せずに。
これが私がこれまでに持っているものです:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Encoder;
private function authAndSend(service:HTTPService):void
{
var encoder:Base64Encoder = new Base64Encoder();
encoder.insertNewLines = false;
encoder.encode("<freshbooks auth token>:X");
//for some reason, freshbooks says that the authentication token
//is the username, and the password could just be a dummy value.
service.headers = {Authorization:"Basic " + encoder.toString()};
service.send();
}
private function freshBooksHandler(event:ResultEvent):void{
txtArea1.text = event.result.toString();
}
]]>
</mx:Script>
<mx:HTTPService id="freshBooksService" url="https://myaccount.freshbooks.com/api/2.1/xml-in"
result="freshBooksHandler(event)" resultFormat="xml">
</mx:HTTPService>
<mx:Button x="59" y="48" label="Button" click="authAndSend(freshBooksService)"/>
<mx:TextArea x="59" y="78" width="401" height="242" id="txtArea1"/>
</mx:Application>
問題は、ボタンをクリックすると、FreshBooks サービスへのユーザー名とパスワードを要求するポップアップがブラウザーに表示されることです。
ユーザー名 (freshbooks によって提供される認証トークン) が、ブラウザーではなく Flex 自体からサーバーに送信されるようにコーディングするにはどうすればよいですか? 私の期待される結果は、ブラウザからのポップアップがなく、freshbooks サーバーが返すものはすべてテキスト領域 (txtArea1) に表示されることです。
注: 認証トークンをブラウザーのポップアップに入力すると、アプリケーションは出力をテキスト領域に正しく表示できます。
ありがとう。