In. net, we know that there is something called WebHttpRequest, which we can use to implement various network spying, monitoring, collection, and robotics. If a pattern recognition is added, that's a big bang... In as, we can also implement the same functions. In addition, we can use JavaScript to perform cross-origin, cookie collection, and other user behavior analysis, which is also a powerful tool in web development. 1. Build communications with external programs 1: generally three steps <1> Use UrlRequest to create a request object. <2> Use UrlLoader to load the request object and then send the request. <3> listen to the UrlLoader object and report the processing result through various events. Ii. Construct UrlRequest. Let's take a look at the common attributes in UrlRequest. 1. url is simple. The request url can be either absolute or relative. 2: Methods written to ajax know whether it is used to control whether the form is submitted by post or get, what get cannot be greater than 2 k, there is no limit to post, and so on. 3: requestHeader we know that all analog submissions will append various parameters to the http head to spoof the server end and disguise itself as a real human request. 4: data is the data attached to the server during the request. It can be in json format or url kv format, but it must be encapsulated using URLVariables. 5: simple demo 1 var url =" http://localhost:25212/index.aspx "; 2 3 var vari: URLVariables = new URLVariables (); 4 5 vari. data = "{\" id \ ": \" 2 \ "}"; 6 7 var req: URLRequest = new URLRequest (url); 8 9 req. data = vari; 10 11 req. method = URLRequestMethod. POST; 3: Construct a UrlLoader object <1>: In as, all urlrequests must be loaded with UrlLoader to interact with backend programs, five events are provided to monitor the status of the current request. 1: Events executed at the start of an open event request 2: progress events often monitor the download progress. You can use byteloaded and bytetotal to view "loaded data" and "total data" in real time ". 3: The complete event called after data is successfully loaded is also the most commonly used event. 4: The ioError event is like ajax. It is called when the request fails. <2>: when data is returned remotely, the data is stored in the data attribute of urlloader. Of course, the type of data returned depends on the URLLoaderDataFormat specified during post. 1: URLLoaderDataFormat. TEXT specifies that the currently returned data value must be a text value, which is also the default value. 2: URLLoaderDataFormat. BINARY the BINARY Attribute must be specified when flash needs to load the BINARY data of the web end. 3: URLLoaderDataFormat. VARIABLES this indicates that the data contained is url-encoded data, so we use VARIABLES for decoding. // Use urlloader to load var loader: URLLoader = new URLLoader (req); loader. addEventListener (Event. COMPLETE, onComplete); loader. addEventListener (IOErrorEvent. IO_ERROR, onError); // function onComplete (e: Event): void {trace (loader. data);} This is basically the case. Next we will conduct an experiment to transmit json to the server for processing by the server. 1: server code. It only returns 1 public partial class Index: System. web. UI. page2 {3 protected void Page_Load (object sender, EventArgs e) 4 {5 var data = Request. form ["data"]; 6 7 Response. write ("congratulations, Data Request succeeded ~ "+ Data); 8} 9} 2: as code 1 import flash.net. URLLoader; 2 import flash.net. URLRequest; 3 import flash. events. event; 4 import flash. text. textField; 5 import flash. utils. timer; 6 import flash. events. timerEvent; 7 8 var url =" http://localhost:25212/index.aspx "; 9 10 var vari: URLVariables = new URLVariables (); 11 12 vari. data = "{\" id \ ": \" 2 \ "}"; 13 14 var req: URLRequest = new URLRequest (url); 15 16 req. data = vari; 17 18 req. method = URLRequestMethod. POST; 19 20 // use urlloader to load 21 var loader: URLLoader = new URLLoader (req); 22 23 loader. addEventListener (Event. COMPLETE, onComplete); 24 loader. addEventListener (IOErrorEvent. IO_ERROR, onError); 25 26 // The request is loaded. 27 function onComplete (e: Event): void {28 trace (loader. data); 29} 30 31 // io request error 32 function onError (e: IOErrorEvent): void {33 trace ("sorry, data Request error"); 34}