本文提供了一个使用flash.net.Socket类连接到套接字的示例:
US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
底部的示例显示了如何使用HTTP请求。
我需要使用HTTP请求.
奖励:这是否适用于HTTPS端口443?
发布于 2011-09-30 04:50:32
套接字不是此作业的正确类。套接字用于处理原始TCP数据连接。例如,您可以使用套接字与使用专有通信协议的自定义服务器组件集成。
相反,使用URLRequest类执行来自flash/actionscript的HTTP请求。这个类支持POST和GET。它还支持HTTPS。
这里是一个处理POST请求的示例。(顺便说一句,这是谷歌在搜索"as3 post请求“时给出的第一个结果)
在文档(上面链接)和网络周围的其他地方也有可用的例子。
编辑:从HTTP检索二进制流数据,您应该使用URLStream。下面这样的内容将通过POST请求来完成:
private var stream:URLStream;
private var uploadData:ByteArray;
public function URLStreamExample() {
stream = new URLStream();
stream.addEventListener(ProgressEvent.PROGRESS, progressHandler);
var request:URLRequest = new URLRequest("URLStreamExample.swf");
request.method = URLRequestMethod.POST;
// uploadData contains the data to send with the post request
// set the proper content type for the data you're sending
request.contentType = "application/octet-stream";
request.data = uploadData;
// initiate the request
stream.load(request);
}
private function progressHandler(event:Event):void {
// called repeatedly as data arrives (just like Socket's progress event)
// URLStream is an IDataInput (just like Socket)
while( stream.bytesAvailable ) {
var b:int = stream.readByte();
}
}https://stackoverflow.com/questions/7605935
复制相似问题