NetConnection.addHeader( )

NetConnection.addHeader( ) MethodFlash 6

adds a header to every AMF packet for a connection
myNetConnectionObject.addHeader(name, mustUnderstand, object)



An arbitrary header name that can be recognized by the server.


A Boolean value that denotes whether the server must process the header before sending a result back to the Flash application.


Any ActionScript object that becomes the header named in the addHeader( ) call.


The addHeader( ) method is useful when you have a specific header that requires server processing, or an arbitrary piece of information that you want attached to every AMF packet, such as a user identification number or session ID.

After using addHeader( ), each subsequent AMF packet from the client will contain the header information. AMF calls returned from the server do not include this header, unless your server-side code processes the header and manually adds it to the return packet.


The following code shows the basic syntax of the addHeader( ) method:

if (connected == null) {
  connected = true;
  var my_conn = NetServices.createGatewayConnection( );
  var my_header = {user:'tom', password:'muck'};
  my_conn.addHeader('myLogin', false, my_header);

In this case, a header named myLogin is added to all AMF packets originating from the client on this connection. The my_header variable contains an ActionScript object that acts as the body of the myLogin header. The server must have the necessary code in place to process this information for it to be useful.

In most cases, you won't use addHeader( ) directly, because the AMF packets are typically not manipulated by your server-side services. A notable exception is a ColdFusion or JRun 4 user-login framework, which uses the setCredentials( ) method on the client. The setCredentials( ) method, however, takes care of calling the addHeader( ) method for you.

See Also

NetConnection.RequestPersistentHeader( ), NetConnection.setCredentials( ); Chapter 4

    Part III: Advanced Flash Remoting