You use the HTTPService class to represent an HTTPService object in ActionScript. When you call the HTTPService object's send() method, it makes an HTTP request to the specified URL, and an HTTP response is returned. Optionally, you can pass parameters to the specified URL. When you do not go through the server-based proxy service, you can use only HTTP GET or POST methods. However, when you set the useProxy property to true and you use the server-based proxy service, you can also use the HTTP HEAD, OPTIONS, TRACE, and DELETE methods.

Note: Due to a software limitation, HTTPService does not generate user-friendly error messages when using GET.

See also:

  • mx.rpc.http.mxml.HTTPService

Static variables

@:value("application/x-www-form-urlencoded")staticfinalread onlyCONTENT_TYPE_FORM:String = "application/x-www-form-urlencoded"

Indicates that the data being sent by the HTTP service is encoded as application/x-www-form-urlencoded.

@:value("application/xml")staticfinalread onlyCONTENT_TYPE_XML:String = "application/xml"

Indicates that the data being sent by the HTTP service is encoded as application/xml.

@:value("DefaultHTTP")staticfinalread onlyDEFAULT_DESTINATION_HTTP:String = "DefaultHTTP"

Indicates that the HTTPService object uses the DefaultHTTP destination.

@:value("DefaultHTTPS")staticfinalread onlyDEFAULT_DESTINATION_HTTPS:String = "DefaultHTTPS"

Indicates that the HTTPService object uses the DefaultHTTPS destination.

@:value("Client.CouldNotDecode")staticfinalread onlyERROR_DECODING:String = "Client.CouldNotDecode"

Indicates that an XML formatted result could not be parsed into an XML instance or decoded into an Object.

@:value("Client.CouldNotEncode")staticfinalread onlyERROR_ENCODING:String = "Client.CouldNotEncode"

Indicates that an input parameter could not be encoded as XML.

@:value("Client.URLRequired")staticfinalread onlyERROR_URL_REQUIRED:String = "Client.URLRequired"

Indicates that the useProxy property was set to false but a url was not provided.

@:value("array")staticfinalread onlyRESULT_FORMAT_ARRAY:String = "array"

The result format "array" is similar to "object" however the value returned is always an Array such that if the result returned from result format "object" is not an Array already the item will be added as the first item to a new Array.

@:value("e4x")staticfinalread onlyRESULT_FORMAT_E4X:String = "e4x"

Deprecated: "RESULT_FORMAT_E4X is not available on this target. RESULT_FORMAT_HAXE_XML is recommended instead."

The result format "e4x" specifies that the value returned is an XML instance, which can be accessed using ECMAScript for XML (E4X) expressions.

@:value("flashvars")staticfinalread onlyRESULT_FORMAT_FLASHVARS:String = "flashvars"

The result format "flashvars" specifies that the value returned is text containing name=value pairs separated by ampersands, which is parsed into an ActionScript object.

@:value("haxexml")staticfinalread onlyRESULT_FORMAT_HAXE_XML:String = "haxexml"

The result format "haxexml" specifies that results should be returned as a Haxe language Xml instance.

See also:

@:value("json")staticfinalread onlyRESULT_FORMAT_JSON:String = "json"

The result format "json" specifies that results should be parsed as JSON.

@:value("object")staticfinalread onlyRESULT_FORMAT_OBJECT:String = "object"

The result format "object" specifies that the value returned is XML but is parsed as a tree of ActionScript objects. This is the default.

@:value("text")staticfinalread onlyRESULT_FORMAT_TEXT:String = "text"

The result format "text" specifies that the HTTPService result text should be an unprocessed String.

@:value("xml")staticfinalread onlyRESULT_FORMAT_XML:String = "xml"

Deprecated: "RESULT_FORMAT_XML is not available on this target. RESULT_FORMAT_HAXE_XML is recommended instead."

The result format "xml" specifies that results should be returned as an flash.xml.XMLNode instance pointing to the first child of the parent flash.xml.XMLDocument.

Constructor

@:value({ destination : null, rootURL : null })new(?rootURL:String, ?destination:String)

Creates a new HTTPService. If you expect the service to send using relative URLs you may wish to specify the rootURL that will be the basis for determining the full URL (one example would be Application.application.url).

Parameters:

rootURL

The URL the HTTPService should use when computing relative URLS.

destination

An HTTPService destination name in the service-config.xml file.

Variables

@:flash.propertychannelSet:ChannelSet

Provides access to the ChannelSet used by the service. The ChannelSet can be manually constructed and assigned, or it will be dynamically created to use the configured Channels for the destination for this service.

@:flash.propertyconcurrency:String

Value that indicates how to handle multiple calls to the same service. The default value is multiple. The following values are permitted:

  • multiple Existing requests are not cancelled, and the developer is responsible for ensuring the consistency of returned data by carefully managing the event stream. This is the default value.
  • single Only a single request at a time is allowed on the operation; multiple requests generate a fault.
  • last Making a request cancels any existing request.

@:flash.propertycontentType:String

Type of content for service requests. The default is application/x-www-form-urlencoded which sends requests like a normal HTTP POST with name-value pairs. application/xml send requests as XML.

@:flash.propertydestination:String

An HTTPService destination name in the services-config.xml file. When unspecified, Flex uses the DefaultHTTP destination. If you are using the url property, but want requests to reach the proxy over HTTPS, specify DefaultHTTPS.

@:flash.propertyheaders:Dynamic

Custom HTTP headers to be sent to the third party endpoint. If multiple headers need to be sent with the same name the value should be specified as an Array.

@:flash.propertymethod:String

HTTP method for sending the request. Permitted values are GET, POST, HEAD, OPTIONS, PUT, TRACE and DELETE. Lowercase letters are converted to uppercase letters. The default value is GET.

@:flash.propertyrequest:Dynamic

Object of name-value pairs used as parameters to the URL. If the contentType property is set to application/xml, it should be an XML document.

@:flash.propertyrequestTimeout:Int

Provides access to the request timeout in seconds for sent messages. A value less than or equal to zero prevents request timeout.

@:flash.propertyresultFormat:String

Value that indicates how you want to deserialize the result returned by the HTTP call. The value for this is based on the following:

  • Whether you are returning XML or name/value pairs.
  • How you want to access the results; you can access results as an object, text, or XML.

The default value is object. The following values are permitted:

  • object The value returned is XML and is parsed as a tree of ActionScript objects. This is the default.
  • array The value returned is XML and is parsed as a tree of ActionScript objects however if the top level object is not an Array, a new Array is created and the result set as the first item. If makeObjectsBindable is true then the Array will be wrapped in an ArrayCollection.
  • xml The value returned is XML and is returned as literal XML in an ActionScript XMLnode object.
  • flashvars The value returned is text containing name=value pairs separated by ampersands, which is parsed into an ActionScript object.
  • text The value returned is text, and is left raw.
  • e4x The value returned is XML and is returned as literal XML in an ActionScript XML object, which can be accessed using ECMAScript for XML (E4X) expressions.

@:flash.propertyrootURL:String

The URL that the HTTPService object should use when computing relative URLs. This property is only used when going through the proxy. When the useProxy property is set to false, the relative URL is computed automatically based on the location of the SWF running this application. If not set explicitly rootURL is automatically set to the URL of mx.messaging.config.LoaderConfig.url.

@:flash.propertyserializationFilter:SerializationFilter

Provides an adapter which controls the process of converting the HTTP response body into ActionScript objects and/or turning the parameters or body into the contentType, URL, and and post body of the HTTP request. This can also be set indirectly by setting the resultFormat by registering a SerializationFilter using the static method: SerializationFilter.registerFilterForResultFormat("formatName", filter)

@:flash.propertyshowBusyCursor:Bool

If true, a busy cursor is displayed while a service is executing. The default value is false.

@:flash.propertyurl:String

Location of the service. If you specify the url and a non-default destination, your destination in the services-config.xml file must allow the specified URL.

@:flash.propertyuseProxy:Bool

Specifies whether to use the Flex proxy service. The default value is false. If you do not specify true to proxy requests though the Flex server, you must ensure that the player can reach the target URL. You also cannot use destinations defined in the services-config.xml file if the useProxy property is set to false.

xmlDecode:Dynamic ‑> Dynamic

Deprecated: "xmlDecode is not available on this target."

ActionScript function used to decode a service result from XML. When the resultFormat is an object and the xmlDecode property is set, Flex uses the XML that the HTTPService returns to create an Object. If it is not defined the default XMLDecoder is used to do the work.

The function referenced by the xmlDecode property must take a flash.xml.XMLNode object as a parameter and should return an Object. It can return any type of object, but it must return something. Returning null or undefined causes a fault.

The following example shows an <mx:HTTPService> tag that specifies an xmlDecode function:

<mx:HTTPService id="hs" xmlDecode="xmlDecoder" url="myURL" resultFormat="object" contentType="application/xml">
	<mx:request><source/>
		<obj>{RequestObject}</obj>
	</mx:request>
</mx:HTTPService>

The following example shows an xmlDecoder function:

function xmlDecoder(myXML) {
	// Simplified decoding logic.
	var myObj = {};
	myObj.name = myXML.firstChild.nodeValue;
	myObj.honorific = myXML.firstChild.attributes.honorific;
	return myObj;
}

xmlEncode:Dynamic ‑> Dynamic

Deprecated: "xmlEncode is not available on this target."

ActionScript function used to encode a service request as XML. When the contentType of a request is application/xml and the request object passed in is an Object, Flex attempts to use the function specified in the xmlEncode property to turn it into a flash.xml.XMLNode object If the xmlEncode property is not set, Flex uses the default XMLEncoder to turn the object graph into a flash.xml.XMLNode object.

The xmlEncode property takes an Object and should return a flash.xml.XMLNode object. In this case, the XMLNode object can be a flash.xml.XML object, which is a subclass of XMLNode, or the first child of the flash.xml.XML object, which is what you get from an <mx:XML> tag. Returning the wrong type of object causes a fault. The following example shows an <mx:HTTPService> tag that specifies an xmlEncode function:

<mx:HTTPService id="hs" xmlEncode="xmlEncoder" url="myURL" resultFormat="object" contentType="application/xml">
	<mx:request><source/>
		<obj>{RequestObject}</obj>
	</mx:request>
</mx:HTTPService>

The following example shows an xmlEncoder function:

function xmlEncoder(myObj) {
	return new XML("<userencoded><attrib0>MyObj.test</attrib0><attrib1>MyObj.anotherTest</attrib1></userencoded>");
}

Methods

@:value({ useWeakReference : false, priority : 0, useCapture : false })addEventListener<T>(type:EventType<T>, listener:T ‑> Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void

Propagate event listeners down to the operation since it is firing some of the events.

disconnect():Void

Disconnects the service's network connection. This method does not wait for outstanding network operations to complete.

logout():Void

Logs the user out of the destination. Logging out of a destination applies to everything connected using the same channel as specified in the server configuration. For example, if you're connected over the my-rtmp channel and you log out using one of your RPC components, anything that was connected over my-rtmp is logged out.

Note: Adobe recommends that you use the mx.messaging.ChannelSet.logout() method rather than this method.

See also:

  • mx.messaging.ChannelSet#logout()

@:value({ useCapture : false })removeEventListener<T>(type:EventType<T>, listener:T ‑> Void, useCapture:Bool = false):Void

Remove event listener on operation added in the addEventListener override.

@:value({ parameters : null })send(?parameters:Dynamic):AsyncToken

Executes an HTTPService request. The parameters are optional, but if specified should be an Object containing name-value pairs or an XML object depending on the contentType.

Parameters:

parameters

An Object containing name-value pairs or an XML object, depending on the content type for service requests.

Returns:

An object representing the asynchronous completion token. It is the same object available in the result or fault event's token property.

@:value({ charset : null })setCredentials(username:String, password:String, ?charset:String):Void

Sets the credentials for the destination accessed by the service. The credentials are applied to all services connected over the same ChannelSet. Note that services that use a proxy to a remote destination will need to call the setRemoteCredentials() method instead.

Parameters:

username

the username for the destination.

password

the password for the destination.

charset

The character set encoding to use while encoding the credentials. The default is null, which implies the legacy charset of ISO-Latin-1. The only other supported charset is "UTF-8".

@:value({ charset : null })setRemoteCredentials(remoteUsername:String, remotePassword:String, ?charset:String):Void

The username and password to authenticate a user when accessing the HTTP URL. These are passed as part of the HTTP Authorization header from the proxy to the endpoint. If the useProxy property is set to is false, this property is ignored.

Parameters:

remoteUsername

the username to pass to the remote endpoint.

remotePassword

the password to pass to the remote endpoint.

charset

The character set encoding to use while encoding the remote credentials. The default is null, which implies the legacy charset of ISO-Latin-1. The only other supported charset is "UTF-8".

Inherited Variables

Defined by AbstractInvoker

@:flash.propertyread onlykeepLastResult:Bool

Flag indicating whether the operation should keep its last call result for later access.

If set to true, the last call result will be accessible through lastResult bindable property.

If set to false, the last call result will be cleared after the call, and must be processed in the operation's result handler. This will allow the result object to be garbage collected, which is especially useful if the operation is only called a few times and returns a large result.

If not set, will use the keepLastResult value of its owning Service, if any, or the default value.

See also:

  • lastResult

  • mx.rpc.AbstractService#keepLastResult

@:flash.propertyread onlylastResult:Dynamic

The result of the last invocation.

@:flash.propertymakeObjectsBindable:Bool

When this value is true, anonymous objects returned are forced to bindable objects.

operationManager:Function

This property is set usually by framework code which wants to modify the behavior of a service invocation without modifying the way in which the service is called externally. This allows you to add a "filter" step on the method call to ensure for example that you do not return duplicate instances for the same id or to insert parameters for performing on-demand paging.

When this is set to a non-null value on the send call, the operationManager function is called instead. It returns the token that the caller uses to be notified of the result. Typically the called function will at some point clear this property temporarily, then invoke the operation again actually sending it to the server this time.

resultElementType:Class<Dynamic>

Like resultType, used to define the ActionScript class used by a given operation though this property only applies to operations which return a multi-valued result (e.g. an Array or ArrayCollection (IList)). This property specifies an ActionScript class for the members of the array or array collection. When you set resultElementType, you do not have to set resultType. In that case, the operation returns an Array if makeObjectsbindable is false and an ArrayCollection otherwise.

resultType:Class<Dynamic>

Specifies an optional return type for the operation. Used in situations where you want to coerce the over-the-wire information into a specific ActionScript class or to provide metadata for other services as to the return type of this operation.

Inherited Methods

Defined by AbstractInvoker

setResult(result:Any):Void

This hook is exposed to update the lastResult property. Since lastResult is ordinarily updated automatically by the service, you do not typically call this. It is used by managed services that want to ensure lastResult always points to "the" managed instance for a given identity even if the the service returns a new copy of the same object.

Parameters:

result

The new value for the lastResult property.