XML.send( ) Method | Flash 5 |
send XML source code to an external script or application |
A string specifying the location of a script or application to which xmlDoc should be sent.
A required string specifying the name of the browser window or frame into which to load the script's response. It can be a custom name or one of the four presets: "_blank", "_ parent", "_self", or "_top". For details, see the description of the window settings under the getURL( ) global function.
The send( ) method converts xmlDoc into a string of XML source code and sends that code in an HTTP request to the script or application residing at url. The specified xmlDoc must be the top-level node in an XML object hierarchy (i.e., an instance of the XML class, not the XMLnode class).
The receiving script or application at url is expected to process the XML in some way and, optionally, return a response�normally a web page�to the browser, which displays it in window. Note that the response is caught not by Flash but by the browser; to catch the response within Flash, use sendAndLoad( ) instead.
When send( ) is invoked from the Flash Player running in a browser, xmlDoc is sent via the POST method. When send( ) is invoked from the Standalone Player on Windows, xmlDoc is sent via the GET method. (See Appendix F for details on support for GET and POST.) The server application receiving the posted XML string must be able to access the raw POST data of the HTTP request directly and should not attempt to parse it as normal name/value pairs. In Perl, the data in a POST request is available from STDIN, and can be extracted and stored in, say, $buffer as follows:
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
In ASP, raw POST data can be accessed via the Request.BinaryRead method.
In PHP 4.1 and later, the following option in php.ini forces raw POST data to be populated regardless of the MIME type of the request:
always_populate_raw_post_data = On
With this option enabled, $HTTP_RAW_POST_DATA will be set for every POST request. Some applications (e.g., versions of Cold Fusion prior to ColdFusion MX) may not have a direct means of accessing the data in a POST request. For these situations, it may be necessary to first convert the XML object to a string using XML.toString( ) and then pass that string to the server as a variable using loadVariables( ).
The default MIME content type of the XML text sent to the server is "application/x-www-form-urlencoded". This type, however, is only cosmetic�the text itself is not URL-encoded. In Flash Player 5.0.41.0 and later, the MIME content type can be modified using the contentType property. For example, to set the MIME type to "application/xml", we use:
xmlDoc = new XML(); xmlDoc.contentType = "application/xml";
Nevertheless, setting the contentType property explicitly to "application/x-www-urlform-encoded" still does not cause the text sent to be URL-encoded.
Note that in Flash Player 5.0.41.0, when XML source is parsed and the characters &, ', ", and < appear in a text node, they are converted to the following entities: &, ', ", and >. Within Flash, the entities are converted back to their original characters when the nodeValue of an element is accessed; however, the entities will show up in XML source sent to the server.
theDoc = new XML("<SEARCH_TERM>tutorials</SEARCH_TERM>"); theDoc.send("http://www.domain.com/cgi-bin/lookup.cgi", "remoteWin");
XML.load( ), XML.loaded, XML.onLoad( ), XML.sendAndLoad( ), XML.status