我是 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 本身而不是浏览器发送到服务器?我的预期结果是浏览器不会弹出任何窗口,并且无论新鲜书服务器返回什么,都将显示在文本区域 (txtArea1) 中。
注意:如果我将身份验证令牌输入到浏览器弹出窗口,应用程序能够正确地将输出显示到文本区域。
谢谢。