听起来你好像在问两个问题。是的,有一种方法可以在Flex中设置HTTP POST的有效负载,并将任何格式的文件上载到服务器:
private function doPost():void
{
var yourData:ByteArray = new ByteArray();
var encoder:Base64Encoder = new Base64Encoder();
for (var i:int = 0; i < 10000; i++)
yourData.writeByte(i);
yourData.position = 0;
encoder.encodeBytes(yourData);
var req:URLRequest = new URLRequest("http://yourdomain.com/yourservice.ext");
req.method = URLRequestMethod.POST;
var postData:URLVariables = new URLVariables();
postData.userData = encoder.flush();
req.data = postData;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, loader_complete);
loader.load(req);
}
private function loader_complete(event:Event):void
{
trace("Upload complete!");
}
... 但这听起来也像是你想要连接,保持连接打开,然后“像插座一样”任意写入;如果是这样的话,那么除了使用Socket类之外,我不相信有内置的机制,不。希望它能有所帮助!