RAD Studio
ContentsIndex
PreviousUpNext
Creating HTTP response messages
Name 
Description 
When the Web server application creates a TWebRequest descended object for an incoming HTTP request message, it also creates a corresponding object descended from TWebResponse to represent the response message that will be sent in return. For example, in NSAPI and ISAPI applications, the response message is encapsulated by a TISAPIResponse object, and Console CGI applications use TCGIResponse objects.
The action items that generate the response to a Web client request fill in the properties of the response object. In some cases, this may be as simple as returning an error code or redirecting the request to another URI. In... more 
Several properties describe the content of the response. ContentType gives the media type of the response, and ContentVersion is the version number for that media type. ContentLength gives the length of the response. If the content is encoded (such as for data compression), indicate this with the ContentEncoding property. If the content came from another URI, this should be indicated in the DerivedFrom property. If the value of the content is time-sensitive, the LastModified property and the Expires property indicate whether the value is still valid. The Title property can provide descriptive information about the content. 
Some of the response header properties describe the capabilities of the Web server application. The Allow property indicates the methods to which the application can respond. The Server property gives the name and version number of the application used to generate the response. The Cookies property can hold state information about the client's use of the server application which is included in subsequent request messages. 
Most of the properties of the TWebResponse object represent the header information of the HTTP response message that is sent back to the Web client. An action item sets these properties from its OnAction event handler.
Not every response message needs to specify a value for every one of the header properties. The properties that should be set depend on the nature of the request and the status of the response.
Use the response object properties for  
When the status code is in the 300-399 range, the client must perform further action before the Web server application can complete its request. If you need to redirect the client to another URI, or indicate that a new URI was created to handle the request, set the Location property. If the client must provide a password before you can proceed, set the WWWAuthenticate property. 
Every response message must include a status code that indicates the status of the response. You can specify the status code by setting the StatusCode property. The HTTP standard defines a number of standard status codes with predefined meanings. In addition, you can define your own status codes using any of the unused possible values.
Each status code is a three-digit number where the most significant digit indicates the class of the response, as follows:
  • 1xx: Informational (The request was received but has not been fully processed).
  • 2xx: Success (The request was received, understood, and accepted).
  • 3xx: Redirection (Further action... more 
If you are sure there is no more work to be done in response to a request message, you can send a response directly from an OnAction event handler. The response object provides two methods for sending a response: SendResponse and SendRedirect. Call SendResponse to send the response using the specified content and all the header properties of the TWebResponse object. If you only need to redirect the Web client to another URI, the SendRedirect method is more efficient.
If none of the event handlers send the response, the Web application object sends it after the dispatcher finishes. However, if... more 
For some requests, the response to the request message is entirely contained in the header properties of the response. In most cases, however, action item assigns some content to the response message. This content may be static information stored in a file, or information that was dynamically produced by the action item or its content producer.
You can set the content of the response message by using either the Content property or the ContentStream property.
The Content property is a string. Delphi strings are not limited to text values, so the value of the Content property can be a string... more 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!