View comments | RSS feed
Packageflash.net
Classpublic final class URLRequestHeader
InheritanceURLRequestHeader Inheritance Object

A URLRequestHeader object encapsulates a single HTTP request header and consists of a name/value pair. URLRequestHeader objects are used in the requestHeaders property of the URLRequest class.

The following request headers cannot be used: Accept-Ranges, Age, Allow, Allowed, Connection, Content-Length, Content-Location, Content-Range, ETag, Host, Last-Modified, Location, Max-Forwards, Proxy-Authenticate, Proxy-Authorization, Public, Range, Retry-After, Server, TE, Trailer, Transfer-Encoding, Upgrade, URI, Vary, Via, Warning, WWW-Authenticate, x-flash-version.

URLRequestHeader objects are restricted in length. If the cumulative length of a URLRequestHeader object (the length of the name property plus the value property) or an array of URLRequestHeader objects used in the URLRequest.requestHeaders property exceeds the acceptable length, Adobe® Flash® Player throws an exception.

View the examples.

See also

URLRequest
URLLoader


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  name : String
An HTTP request header name (such as Content-Type or SOAPAction).
URLRequestHeader
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  value : String
The value associated with the name property (such as text/plain).
URLRequestHeader
Public Methods
 MethodDefined by
  
URLRequestHeader(name:String = "", value:String = "")
Creates a new URLRequestHeader object that encapsulates a single HTTP request header.
URLRequestHeader
 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
 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
Property detail
nameproperty
public var name:String

An HTTP request header name (such as Content-Type or SOAPAction).

valueproperty 
public var value:String

The value associated with the name property (such as text/plain).

Constructor detail
URLRequestHeader()constructor
public function URLRequestHeader(name:String = "", value:String = "")

Creates a new URLRequestHeader object that encapsulates a single HTTP request header. URLRequestHeader objects are used in the requestHeaders property of the URLRequest class.

Parameters
name:String (default = "") — An HTTP request header name (such as Content-Type or SOAPAction).
 
value:String (default = "") — The value associated with the name property (such as text/plain).
Examples

The following example adds a single HTTP request header to an array in a URLRequest object and then loads data from an XML file and displays event information. Highlights of the example follow:
  1. The constructor function creates a URLLoader instance named loader and a URLRequest instance named request, which contains the location and name of the file to be loaded.
  2. The loader object is passed to the configureListeners() method, which adds listeners for each of the supported URLLoader events.
  3. The example creates a URLRequestHeader instance with the parameters name = pragma and value = no-cache.
  4. The HTML request header is then added to the end of the requestHeaders array.
  5. Then request is passed to the loader.load() method, which loads the XML file.

Note: To run the example, put a file named XMLFile.xml in the same directory as your SWF file.

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestHeader;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;

    public class URLRequestHeaderExample extends Sprite {
        public function URLRequestHeaderExample() {
            var loader:URLLoader = new URLLoader();
            configureListeners(loader);

            var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
            var request:URLRequest = new URLRequest("http://www.[yourdomain].com/greeting.cfm");
            request.data = new URLVariables("name=John+Doe");
            request.method = URLRequestMethod.POST;
            request.requestHeaders.push(header);
            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);
        }
    }
}




Comments


djtechwriter said on Jun 28, 2006 at 5:13 PM :
The following request headers not mentioned in the overview also cannot be used:

Referer, Get, Post, Put, Delete, Options, and Trace.

Dave Jacowitz
Flash Team
djtechwriter said on Jun 29, 2006 at 2:05 PM :
Restricted terms are not case-sensitive (so GET, Get, and get are all restricted).

 

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

Current page: http://livedocs.adobe.com/flex/2/langref/flash/net/URLRequestHeader.html