本文提供了使用flash.net.Socket类连接套接字的示例:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
底部的示例展示了如何使用HTTP-GET请求。
我需要使用HTTP-POST请求。
额外奖励:这是否适用于HTTPS端口443?
我需要使用HTTP-POST请求。
额外奖励:这是否适用于HTTPS端口443?
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();
}
}
POST /path/to/resource.mov HTTP/1.1
,然后是必要的头部(根据你的具体需求可能有很多可能性)。接着是一个空行(CRLF),最后是你的POST数据(必须与你发送的头部匹配,特别是content-type和content-length)。HTTPS则更加复杂,所以你需要自己解决。(或者,查看我上面的编辑,使用URLRequest进行流式传输的示例)。 - Lee