| Package | flash.net |
| Class | public final class URLRequest |
| Inheritance | URLRequest Object |
load() methods of URLStream, URLLoader, Loader and
other loading operations to initiate URL downloads, as well as to the upload()
and download() methods of the FileReference class.
By default, the URL that you pass to the url parameter must be in
exactly the same domain as the calling SWF file, including subdomains. For example, www.adobe.com and
store.adobe.com are different domains. To load data from a different domain,
place a cross-domain policy file on the server that is hosting the SWF file.
When you use this class, consider the Adobe® Flash® Player security model:
For more information, see the following:
See also
| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| contentType : String
The MIME content type of any
POST data. | URLRequest | ||
| data : Object
An object containing data to be transmitted with the URL request.
| URLRequest | ||
| method : String
Controls whether the HTTP form submission method is a
GET
or POST operation. | URLRequest | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| requestHeaders : Array
The array of HTTP request headers to be appended to the
HTTP request.
| URLRequest | ||
| url : String
The URL to be requested.
| URLRequest | ||
| Method | Defined by | ||
|---|---|---|---|
|
URLRequest(url:String = null)
Creates a URLRequest object.
| URLRequest | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
| contentType | property |
contentType:String [read-write]
The MIME content type of any POST data.
Note:The FileReference.upload() and
FileReference.download() methods do not
support the URLRequest.contentType parameter.
public function get contentType():String
public function set contentType(value:String):void
| data | property |
data:Object [read-write]An object containing data to be transmitted with the URL request.
This property is used with the method property.
If the value of URLRequest.method is POST,
the data is transmitted with the URLRequest object with the HTTP POST method.
If the value of URLRequest.method is GET,
the data defines variables to be sent with the URLRequest object with
the HTTP GET method.
The URLRequest API offers binary POST support and support for URL-encoded variables,
as well as support for strings. The data object can be of ByteArray, URLVariables,
or String type.
The way in which the data is used depends on the type of object used:
POST data. For GET, data of ByteArray type
is not supported. Also, data of ByteArray type is not supported for
FileReference.upload() and FileReference.download().POST,
the variables are encoded using x-www-form-urlencoded format
and the resulting string is used as POST data. An exception is a call to
FileReference.upload(), in which the variables are sent as separate fields in
a multipart/form-data post.GET,
the URLVariables object defines variables to be sent with the URLRequest object.POST or GET data.This data is not sent until a method, such as navigateToURL()
or FileReference.upload(), uses the URLRequest object.
public function get data():Object
public function set data(value:Object):void
See also
Highlights of the example follow:
request, taking the URL of the remote application as a parameter.data property of the URLRequest object.navigateToURL, which opens a new browser window
to the remote application's URL.Note: To run the example, the remote application URL in the example must be replaced with a working URL. Additionally, you would need server code to process the information captured by Flash Player in the URLVariables object.
package {
import flash.display.Sprite;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
public class URLVariablesExample extends Sprite {
public function URLVariablesExample() {
var url:String = "http://www.[yourDomain].com/application.jsp";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.exampleSessionId = new Date().getTime();
variables.exampleUserLabel = "guest";
request.data = variables;
navigateToURL(request);
}
}
}
| method | property |
method:String [read-write]
Controls whether the HTTP form submission method is a GET
or POST operation.
Valid values are URLRequestMethod.GET or URLRequestMethod.POST.
The default value is URLRequestMethod.GET.
public function get method():String
public function set method(value:String):void
ArgumentError — If the value parameter is not
URLRequestMethod.GET or URLRequestMethod.POST.
|
See also
URLRequest.method property to
URLRequestMethod.POST.
Highlights of the example follow:
request, taking the URL of the remote application as a parameter.data property of the URLRequest object.URLRequest.method property is set to
URLRequestMethod.POST.navigateToURL, which opens a new browser window
to the remote application's URL.Note: To run the example, the remote application URL in the example must be replaced with a working URL. Additionally, you would need server code to process the information captured by Flash Player in the URLVariables object.
package {
import flash.display.Sprite;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
public class URLRequest_method extends Sprite {
public function URLRequest_method() {
var url:String = "http://www.[yourDomain].com/application.jsp";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.exampleSessionId = new Date().getTime();
variables.exampleUserLabel = "guest";
request.data = variables;
request.method = URLRequestMethod.POST;
navigateToURL(request);
}
}
}
| requestHeaders | property |
requestHeaders:Array [read-write]The array of HTTP request headers to be appended to the HTTP request. The array is composed of URLRequestHeader objects. Each object in the array must be a URLRequestHeader object that contains a name string and a value string, as follows:
var rhArray:Array = new Array(new URLRequestHeader("Content-Type", "text/html"));
Flash Player imposes certain restrictions on request headers; for more information, see the URLRequestHeader class description.
The FileReference.upload() and FileReference.download()
methods do not
support the URLRequest.requestHeaders parameter.
public function get requestHeaders():Array
public function set requestHeaders(value:Array):void
See also
| url | property |
url:String [read-write]The URL to be requested. By default, the URL must be in exactly the same domain as the calling SWF file, including subdomains. For example, SWF files at www.adobe.com and store.adobe.com are in different domains. To load data from a different domain, put a cross-domain policy file on the server that is hosting the SWF file. For more information, see the security documentation described in the URLRequest class description.
Implementation public function get url():String
public function set url(value:String):void
| URLRequest | () | constructor |
public function URLRequest(url:String = null)
Creates a URLRequest object.
If System.useCodePage is true, the request is encoded using the
system code page, rather than Unicode.
If System.useCodePage is false, the request is encoded using Unicode, rather than the
system code page.
url:String (default = null) — The URL to be requested. You can set the URL later by using the url property.
|
See also
complete event is dispatched and the data in the XML
file traces to the output. Additional event handlers capture other events, including error
events.
To run this example, place a file named XMLFile.xml in the same directory as your SWF file.
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class URLRequestExample extends Sprite {
public function URLRequestExample() {
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("XMLFile.xml");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
}
}