Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: e033528c84
Fetching contributors…

Cannot retrieve contributors at this time

executable file 91 lines (82 sloc) 3.452 kB
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns="*" creationComplete="useHttpService()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.http.HTTPService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.external.*;
private var socket:Socket;
public function useHttpService():void {
socket = new Socket();
ExternalInterface.call("log", "Connecting back to malaria server...");
socket.addEventListener(Event.CONNECT, this.connectHandler);
socket.addEventListener(ProgressEvent.SOCKET_DATA, this.onData);
socket.connect("localhost", 8081);
}
private function onData(event:ProgressEvent):void
{
ExternalInterface.call("log", "Got data from proxy");
var data:String = socket.readUTFBytes(socket.bytesAvailable);
handle(data);
}
public function connectHandler(event:Event):void
{
ExternalInterface.call("log", "Connected and ready");
socket.writeUTFBytes("Hello");
socket.flush();
}
public function handle(data:String):void {
var regresult:Object = /([^ ]+) ([^ ]+) ([^ ]+)( (.*))?/.exec(data);
var verb:String = regresult[1];
var url:String = regresult[2];
var accept:String = regresult[3];
var reqData:String = regresult[5];
ExternalInterface.call("log", "Trying: [" + verb + " " + url + " " + accept + " " + (verb == "POST" ? " " + reqData : "") + "]");
var urlRequest:URLRequest = new URLRequest(url);
urlRequest.method = (verb == "POST") ? URLRequestMethod.POST : URLRequestMethod.GET;
if (reqData != null && reqData != "") {
urlRequest.data = new URLVariables(reqData);
}
//urlRequest.requestHeaders.push(new URLRequestHeader("Accept", accept));
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(urlRequest);
ExternalInterface.call("log", "Sent");
}
public function toNameValuePairs(reqData:String):Object {
var parts:Object = reqData.split("&");
var result:Object = {};
for(var i:String in parts) {
var pparts:Object = i.split("=", 2);
result[pparts[0]] = (pparts.length == 2 ? pparts[1] : "");
}
return result;
}
public function onComplete(event:Event):void {
socket.writeUTFBytes(event.target.bytesTotal + ":");
socket.writeBytes(event.target.data);
socket.flush();
ExternalInterface.call("log", "Sending back data - length " + event.target.bytesTotal + " (" + event.target.data.length + ")");
}
public function onIOError(event:IOErrorEvent):void {
ExternalInterface.call("log", "Fault");
var faultstring:String = event.text;
ExternalInterface.call("log", "FAULT:" + faultstring);
socket.writeUTFBytes("HTTP/1.1 502 Not accessible - " + event.text);
socket.flush();
ExternalInterface.call("log", "Sending back 502");
}
]]>
</mx:Script>
</mx:Application>
Jump to Line
Something went wrong with that request. Please try again.