View comments | RSS feed

send (XML.send method)

public send(url:String, [target:String], [method:String]) : Boolean

Encodes the specified XML object into an XML document and sends it to the specified target URL.

When using this method, consider the Flash Player security model:

For more information, see the following:

Availability: ActionScript 1.0; Flash Player 5

Parameters

url:String - The destination URL for the specified XML object.

target:String [optional] - The browser window to show data that the server returns:

If you do not specify a target parameter, it is the same as specifying _self.

method:String [optional] - the method of the HTTP protocol used: either "GET" or "POST". In a browser, the default value is "POST". In the Flash test environment, the default value is "GET".

Returns

Boolean - false if no parameters are specified, true otherwise.

Example

The following example defines an XML packet and sets the content type for the XML object. The data is then sent to a server and shows a result in a browser window.

var my_xml:XML = new XML("<highscore><name>Ernie</name><score>13045</score></highscore>");
my_xml.contentType = "text/xml";
my_xml.send("http://www.flash-mx.com/mm/highscore.cfm", "_blank");

Press F12 to test this example in a browser.

See also

sendAndLoad (XML.sendAndLoad method)


Version 8

Comments


No screen name said on Feb 9, 2006 at 5:38 AM :
This example indicates the XML data is sent to a coldfusion template, highscore.cfm. Could the code for this document be included somewhere in the documentation so users can see how to interpet the XML data in coldfusion? I have been unable to find any documentation as to how the XML data object sent from flash is usable with coldfusion.
peterd_mm said on Feb 9, 2006 at 2:13 PM :
The code for highscore.cfm is included below, and may be a bit basic, but it works.

<cfsetting enablecfoutputonly="Yes">
<cfscript>
success = true;
// sample packet: <highscore><name>Ernie</name><score>13045</score><highscore>
try {
switch (CGI.REQUEST_METHOD) {
case 'POST':
XmlRequest = getHTTPRequestData( ).content;
break;
case 'GET':
XmlRequest = CGI.QUERY_STRING;
break;
}
XmlRequest = XmlParse(XmlRequest);
Variables.name = XmlRequest.XmlRoot.name.XmlText;
Variables.score = XmlRequest.XmlRoot.score.XmlText;
} catch (Any e) {
errorMessage = e.Message;
success = false;
}
</cfscript>
<cfif success>
<cfoutput><h1>Congratulations to #Variables.name# who scored #Val(Variables.score)# points!</h1></cfoutput>
<cfelse>
<cfoutput><h2 style="color:##FF0000;">Unable to locate XML packet in either GET or POST scope.</h2>
<ul><li>#errorMessage#</li></ul></cfoutput>
</cfif>
<cfsetting enablecfoutputonly="No">

The code begins with a switch statement which determines how the data was submitted. If the CGI.REQUEST_METHOD is POST, the XML packet is passed in the HTTP request as #getHTTPRequestData().content#. If the CGI.REQUEST_METHOD is GET, the same XML would have been passed in the query string as CGI.QUERY_STRING.
Next you parse the XML string into a CF XML object using #XmlParse()# and the values are accessed using ColdFusion.

Hope that helps. The only real "trick" in the process is the #getHTTPRequestData()# which is explained in the ColdFusion documentation on LiveDocs at http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000482.htm.

Peter
Lacrymocéphale said on Apr 20, 2006 at 8:53 AM :
Notice that '&' caracter is replaced by its entity '&amp;' just before the sending.
So you can't send a simple textNode like XML("login=name&pass=word") to perform the same HTTP request that a <form method="POST"> do.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002878.html