Pacoteflash.net
Classepublic final class URLRequest
HerançaURLRequest Inheritance Object

The URLRequest class captures all of the information in a single HTTP request. URLRequest objects are passed to the load() methods of the Loader, URLStream, and URLLoader classes as well as in other loading operations to initiate URL downloads, as well as to the upload() and download() methods of the FileReference class.

When you use this class in content running in Flash Player, consider the following security model:

However, in the Adobe Integrated Runtime, content in the application security sandbox (content installed with the AIR application) are not restricted by these security limitations.

For content running in the Adobe Integrated Runtime, files in the application security domain — files installed with the AIR application — can access URLs using any of the following URL schemes:

Content running in Adobe Integrated Runtime that is not in the application security domain observes the same restrictions as SWF content running in Flash Player (in the browser), and loading is governed by the content's domain and any permissions granted in cross-domain policy files.

For more information, see the following:

Veja Exemplos

Veja também

flash.html.HTMLLoader
flash.net.FileReference
flash.net.URLLoader
flash.net.URLRequestHeader
flash.net.URLStream


Propriedades Públicas
 PropriedadeDefinido por
  authenticate : Boolean
Specifies whether authentication requests should be handled (true or not (false) for this request.
URLRequest
  cacheResponse : Boolean
Specifies whether successful response data should be cached for this request.
URLRequest
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  contentType : String
The MIME content type of the content in the the data property.
URLRequest
  data : Object
An object containing data to be transmitted with the URL request.
URLRequest
  followRedirects : Boolean
Specifies whether redirects are to be followed (true) or not (false).
URLRequest
  manageCookies : Boolean
Specifies whether the HTTP protocol stack should manage cookies for this request.
URLRequest
  method : String
Controls the HTTP form submission method.
URLRequest
 Inheritedprototype : 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
  useCache : Boolean
Specifies whether the local cache should be consulted before this URLRequest fetches data.
URLRequest
  userAgent : String
Specifies the user-agent string to be used in the HTTP request.
URLRequest
Métodos Públicos
 MétodoDefinido por
  
URLRequest(url:String = null)
Creates a URLRequest object.
URLRequest
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
Specifies authentication credentials to use for the request.
URLRequest
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Detalhes da propriedade
authenticatepropriedade
authenticate:Boolean  [read-write]

Specifies whether authentication requests should be handled (true or not (false) for this request. If false, authentication challenges return an HTTP error.

The supported authentication methods are:

Note:The FileReference.upload(), FileReference.download(), and HTMLLoader.load() methods do not support the URLRequest.authenticate property.

The default value is true.


Implementação
    public function get authenticate():Boolean
    public function set authenticate(value:Boolean):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

cacheResponsepropriedade 
cacheResponse:Boolean  [read-write]

Specifies whether successful response data should be cached for this request.

Note:The HTMLLoader.load() method does not support the URLRequest.cacheResponse property.

The default value is true.


Implementação
    public function get cacheResponse():Boolean
    public function set cacheResponse(value:Boolean):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

contentTypepropriedade 
contentType:String  [read-write]

The MIME content type of the content in the the data property.

Note:The FileReference.upload(), FileReference.download(), and HTMLLoader.load() methods do not support the URLRequest.contentType property.


Implementação
    public function get contentType():String
    public function set contentType(value:String):void

Veja também

datapropriedade 
data:Object  [read-write]

An object containing data to be transmitted with the URL request.

This property is used with the method property. In the Adobe Integrated Runtime, data is sent when any HTTP method other than GET is used. In Flash Player, data is set when the POST HTTP method is used.

The URLRequest API offers binary POST support and support for URL-encoded variables, as well as support for strings. The data object can be a ByteArray, URLVariables, or String object.

The way in which the data is used depends on the type of object used:

This data is not sent until a method, such as navigateToURL() or FileReference.upload(), uses the URLRequest object.


Implementação
    public function get data():Object
    public function set data(value:Object):void

Veja também


Exemplo

The following exemplo opens the remote application hosted at http://www.[yourDomain].com/application.jsp in a new browser window and passes data about a user session, captured in a URLVariables object, to the application.

Highlights of the exemplo follow:

  1. The constructor function creates a URLRequest instance named request, taking the URL of the remote application as a parameter.
  2. A URLVariables object is created and two of its properties are assigned values.
  3. The URLVariables object is assigned to the data property of the URLRequest object.
  4. The exemplo calls navigateToURL, which opens a new browser window to the remote application's URL.

Note: To run the exemplo, the remote application URL in the exemplo 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);
        }
    }
}
followRedirectspropriedade 
followRedirects:Boolean  [read-write]

Specifies whether redirects are to be followed (true) or not (false).

Note:The FileReference.upload(), FileReference.download(), and HTMLLoader.load() methods do not support the URLRequest.followRedirects property.

The default value is true.


Implementação
    public function get followRedirects():Boolean
    public function set followRedirects(value:Boolean):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

manageCookiespropriedade 
manageCookies:Boolean  [read-write]

Specifies whether the HTTP protocol stack should manage cookies for this request. When true, cookies are added to the request and response cookies are remembered. If false, cookies are not added to the request and response cookies are not remembered, but users can manage cookies themselves by direct header manipulation.

On Mac OS, cookies are shared with Safari. To clear cookies on Mac OS:

  1. Open Safari.
  2. Select Safari > Preferences, and click the Security panel.
  3. Click the Show Cookies button.
  4. Click the Reomove All button.

To clear cookies on Windows:

  1. Open the Internet Properties control panel, and click the General tab.
  2. Click the Delete Cookies button.

Note:The FileReference.upload(), FileReference.download(), and HTMLLoader.load() methods do not support the URLRequest.manageCookies property.

The default value is true.


Implementação
    public function get manageCookies():Boolean
    public function set manageCookies(value:Boolean):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

methodpropriedade 
method:String  [read-write]

Controls the HTTP form submission method.

For SWF content running in Flash Player (in the browser), this property is limitted to GET or POST operation, and valid values are URLRequestMethod.GET or URLRequestMethod.POST. For content running in the Adobe Integrated Runtime, if the content is in the application security domain, you can use any string value; otherwise (if the content is not in the AIR application security domain) you are still restricted to using GET or POST.

The default value is URLRequestMethod.GET.


Implementação
    public function get method():String
    public function set method(value:String):void

Throws
ArgumentError — If the value parameter is not URLRequestMethod.GET or URLRequestMethod.POST.

Veja também


Exemplo

The following exemplo opens the remote application hosted at http://www.[yourDomain].com/application.jsp in a new browser window and passes data about a user session, captured in a URLVariables object, to the application. It explicitly sets the value of the URLRequest.method property to URLRequestMethod.POST.

Highlights of the exemplo follow:

  1. The constructor function creates a URLRequest instance named request, taking the URL of the remote application as a parameter.
  2. A URLVariables object is created and two of its properties are assigned values.
  3. The URLVariables object is assigned to the data property of the URLRequest object.
  4. The value of the URLRequest.method property is set to URLRequestMethod.POST.
  5. The exemplo calls navigateToURL, which opens a new browser window to the remote application's URL.

Note: To run the exemplo, the remote application URL in the exemplo 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);
        }
    }
}
requestHeaderspropriedade 
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.


Implementação
    public function get requestHeaders():Array
    public function set requestHeaders(value:Array):void

Veja também

urlpropriedade 
url:String  [read-write]

The URL to be requested.

For content running in Flash Player and content running in the Adobe Integrated Runtime that is not in the application security sandbox, by default, the URL must be in exactly the same domain as the calling file, including subdomains. For exemplo, 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 data. For more information, see the security documentation described in the URLRequest class description.

For content running in Adobe Integrated Runtime, files in the application security domain — files installed with the AIR application — can access URLs using any of the following URL schemes:

Note: Flash Player Update 3 and later versions supports IPv6 (Internet Protocol version 6). IPv6 is a version of Internet Protocol that supports 128-bit addresses (an improvement on the earlier IPv4 protocol that supports 32-bit addresses). You might need to activate IPv6 on your networking interfaces. For more information, see the Help for the operating system hosting the data. If IPv6 is supported on the hosting system, you can specify numeric IPv6 literal addresses in URLs enclosed in brackets ([]), as in the following:

     rtmp://[2001:db8:ccc3:ffff:0:444d:555e:666f]:1935/test
     


Implementação
    public function get url():String
    public function set url(value:String):void
useCachepropriedade 
useCache:Boolean  [read-write]

Specifies whether the local cache should be consulted before this URLRequest fetches data.

Note:The HTMLLoader.load() method does not support the URLRequest.useCache property.

The default value is true.


Implementação
    public function get useCache():Boolean
    public function set useCache(value:Boolean):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

userAgentpropriedade 
userAgent:String  [read-write]

Specifies the user-agent string to be used in the HTTP request.

The default value is the same user agent string that is used by Flash Player, which is different on Mac and Windows.

Note: This property does not affect the user agent string when the URLRequest object is used with the load() method of an HTMLLoader object. To set the user agent string for an HTMLLoader object, set the userAgent property of the HTMLLoader object or set the static URLRequestDefaults.userAgent property.


Implementação
    public function get userAgent():String
    public function set userAgent(value:String):void

Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

Detalhes do construtor
URLRequest()Construtor
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.

Parâmetros
url:String (default = null) — The URL to be requested. You can set the URL later by using the url property.

Veja também

Detalhes do método
setLoginCredentials()método
public function setLoginCredentials(user:String, password:String):void

Specifies authentication credentials to use for the request.

Note for applications running on MacOS: On MacOS, when you set credentials for a URLRequest object, the application uses these credentials for the host specified by that object until the application is closed, even if you call setLoginCredentials() for a new URLRequest object pertaining to the same host. A host is a domain, such as "www.exemplo.com", or a domain and a port number, such as "www.exemplo.com:80". Note that "exemplo.com", "www.exemplo.com", and "sales.exemplo.com" are each considered unique hosts. However, if a server rejects the credentials specified by this method, then a subsequent call to the setLoginCredentials() method (for the same host) will be recognized.

Parâmetros

user:String — The user name to use for the request.
 
password:String — The password to use for the request.


Throws
SecurityError — The caller is not in the AIR application security sandbox.

Veja também

Exemplos How to use examples
URLRequestExample.as

The following exemplo creates a new Loader object and passes it a URLRequest object that contains the path to an XML file. If the loading operation is successful, a 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 exemplo, 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);
        }
    }
}