Response Object

Description

The Response Object provides a set of methods and properties for controlling what information is sent to the requesting browser in response to the request. This includes sending information directly to the browser, redirecting the browser to another URL, or setting cookie values.

You use the Response object to control the information you send to a user. This includes sending information directly to the browser, redirecting the browser to another URL, or setting cookie values.

Syntax

Response.property|method([parameters])

Properties

Buffer Indicates whether to buffer script output.
CacheControl Determines whether proxy servers are able to cache the output generated by FoxWeb scripts.
Charset Appends the character set name to the HTTP header.
ContentType Specifies the HTTP content type for the current output.
Expires Specifies the timeout after which a page cached on a browser expires.
ExpiresAbsolute Specifies the date and time after which a page cached on a browser expires.
OutputBuffer Returns the contents of the buffer, which is about to be written to the client.
Status Determines the status line returned in the HTTP header.

Methods

AddHeader Adds a name=value line to the HTTP header returned to the browser.
Clear Clears the content of the output buffer.
DelCookie Instructs the browser to delete a cookie.
End Stops processing the FoxWeb script and returns the current content.
Flush Sends the content of the output buffer to the browser immediately.
Redirect Sends a redirect message to the browser, causing it to attempt to connect to a different URL.
SetCookie Sends a cookie to the browser.
Write Sends content to the browser, or appends content to the output buffer, depending on the Response.Buffer setting.

Buffer Property

Description

The Response.Buffer property indicates whether script output should be buffered. When script output is buffered, the server does not send a response to the client until the current scripts has been processed, or until the Response.Flush or Response.End method has been called.

This property is read/write.

Syntax

Response.Buffer = lFlag


CacheControl Property

Description

The Response.CacheControl property sets or returns the value of the cache-control HTTP header, which determines whether proxy servers can cache output returned by the script. The default value for this property is "Private", which instructs proxy servers not to cache output.

This property is read/write.

Syntax

Response.CacheControl = cHeader

Parameters

cHeader
A character value that determines the cache-control setting. This can be either "Private" (the default), or "Public".

Remarks

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


Charset Property

Description

The Response.Charset property appends the name of the character set (for example "ISO-8859-1") to the content-type header in the response object.

This property is read/write.

Syntax

Response.Charset = cCharset

Parameters

cCharset
A character value that determines the character set.

Remarks

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


ContentType Property

Description

The Response.ContentType property sets or returns the value of the Content-Type HTTP header, which informs the browser of the kind of data included in the reply. It can be used to serve non-HTML data from FoxWeb scripts.

This property is read/write.

Syntax

Response.ContentType = cContentType

Parameters

cContentType
A character value that determines the Content-Type setting. Some common values for this property can be found in the Returning Content to the Browser topic.

Remarks

The default value for this property is "text/html".

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


Expires Property

Description

The Response.Expires property sets the length of time before a page cached on a browser expires. If the user requests the same script before it expires, the cached version is displayed.

In VFP 6.0 and above this property is write only. The actual expiration timestamp can be obtained from Response.ExpiresAbsolute.

In versions of VFP prior to 6.0 this property is read/write.

Syntax

Response.Expires = nMinutes

Parameters

nMinutes
A numeric value, specifying the time in minutes before a page expires.

Remarks

Different browsers behave differently when a page expires. For example Netscape Navigator does not even allow viewing an expired page when the back button is pressed. Internet Explorer, on the other hand, does allow the viewing of an expired page when the back button is pressed. Both browsers request a new copy of the page from the server, if the user clicks on a link, pointing to that page.

Due to differences in the system time setting between the server and the browser, it is possible that you will not get the desired behavior when you set this property.

A value of 0 will cause the browser to expire the page immediately. This setting will always work regardless of differences in the system time setting between the server and the browser, because it sets the expiration date to 1990.

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


ExpiresAbsolute Property

Description

The Response.ExpiresAbsolute sets the exact date and time, when a page cached on a browser expires. If the user requests the same script before it expires, the cached version is displayed.

This property is read/write.

Syntax

Response.ExpiresAbsolute = tExpirationDateTime

Parameters

tExpirationDateTime
A DateTime or Date value, specifying the date and time after which a page expires.

Remarks

Different browsers behave differently when a page expires. For example Netscape Navigator does not even allow viewing an expired page when the back button is pressed. Internet Explorer, on the other hand, does allow the viewing of an expired page when the back button is pressed. Both browsers request a new copy of the page from the server, if the user clicks on a link, pointing to that page.

Due to differences in the system time setting between the server and the browser, it is possible that you will not get the desired behavior when you set this property.

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


OutputBuffer Property

Description

The Response.OutputBuffer property can be used to modify the output that is about to be returned to the client.

This property is read/write.

Syntax

Response.OutputBuffer = cOutput

Parameters

cOutput
A character value, specifying the modifiled content.

Remarks

This property should not be used to create new content. Use Response.Write instead.

Example

<%=Response.OutputBuffer = STRTRAN(Response.OutputBuffer, CHR(13), "")%>

The code in the above example strips all carriage returns from the output.


Status Property

Description

The Response.Status property specifies the value of the status line returned by the server. Status values are defined in the HTTP specification.

This property is read/write.

Syntax

Response.Status = cStatusHeader

Parameters

cStatusHeader
A character value, specifying the HTTP status header that should be sent to the browser, e.g.: Response.Status = "401 Unauthorized".

Remarks

The default value for the status property is "200 OK"

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to set this property after you have already sent content to the browser, FoxWeb will return an error message.


AddHeader Method

Description

The Response.AddHeader method adds an HTTP header with a specified value. Once a header has been added, it cannot be removed.

Syntax

Response.AddHeader(cHeaderName, cHeaderValue)

Parameters

cHeaderName
A character value indicating the name of the header variable.
cHeaderValue
A character value indicating the value of the header variable.

Remarks

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to use this method after you have already sent content to the browser, FoxWeb will return an error message.


Clear Method

Description

The Response.Clear method clears the output buffer, by erasing all content.

Syntax

Response.Clear

Remarks

This method erases only the response body -- it does not erase response headers.


DelCookie Method

Description

The Response.DelCookie method instructs the browser to forget a cookie that was previously sent to it.

Syntax

Response.DelCookie(cCookieName, [cCookiePath], [cCookieDomain])

Parameters

cCookieName
A character value indicating the name of the cookie being deleted.
cCookiePath
A character value indicating the path associated with the cookie being deleted. In order for the method to be successful, this value must match the path that was associated with the cookie, when it was sent to the browser. If this parameter is omitted then the path of the current script is used.
cCookieDomain
A character value indicating the domain associated with the cookie being deleted. In order for the method to be successful, this value must match the domain that was associated with the cookie, when it was sent to the browser. In most cases you will not be associating a domain with cookies you send to the browser, so generally this parameter will be omitted.

Remarks

This method works by re-sending the cookie to the browser, specifying an expiration date that is in the past.

Cookie headers are part of the HTTP header, so they must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to use this method after you have already sent content to the browser, FoxWeb will return an error message.


End Method

Description

The Response.End method instructs FoxWeb to stop processing the script and return the current result to the browser. The remaining contents of the script are not processed.

Syntax

Response.End

Remarks

If this method is included in a top-level script, it is equivalent to the RETURN command; however, the RETURN command would not work in a procedure or script, called by another script, because it would not stop script processing, but would simply return control to the calling procedure.


Flush Method

Description

The Response.Flush method instructs FoxWeb to send buffered output immediately.

Syntax

Response.Flush

Remarks

This method can be used to send output to the browser at specific stages of script execution, without having to disable output buffering. It is useful in cases where you want to inform the user about the progress of the script, or in cases where you want to send partial results while the script is executing.


Redirect Method

Description

The Response.Redirect method instructs the browser to connect to a different URL.

Syntax

Response.Redirect(cURL)

Parameters

cURL
A character value indicating the URL that the browser should be redirected to, e.g.: Response.Redirect("http://www.foxweb.com")

Remarks

This method works by sending a 302 Object Moved status header to the browser.

All HTTP headers must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to use this method after you have already sent content to the browser, FoxWeb will return an error message.


SetCookie Method

Description

The Response.SetCookie method sends a cookie to the browser. For more information on cookies and the various parameters of this method refer to the Session Management topic.

Syntax

Response.SetCookie(cCookieName, cCookieValue, [tCookieExpires], [cCookiePath], [cCookieDomain], [lCookieSecure], [lHttpOnly], [cSameSite])

Parameters

cCookieName
A character value indicating the cookie name.
cCookieValue
A character value indicating the contents of the cookie.
tCookieExpires
A DateTime or Date value indicating the expiration Date and Time of the cookie. This parameter must be set in order for the cookie to be stored on the browser's disk after the session ends. If this attribute is not set to a date beyond the current date, the cookie will expire when the browser is restarted.
cCookiePath
A character value indicating the path associated with the cookie. If specified, the cookie is sent only to requests to this path and its sub-paths. If this parameter is not specified, then the current path is used.
cCookieDomain
A character value indicating the domain associated with the cookie.
lCookieSecure
A logical value indicating whether the cookie is secure. If this parameter is set to .T. then the browser will not return the cookie via a non-secure connection.
lHttpOnly
A logical value indicating whether the cookie should have an HttpOnly attribute. If this parameter is set to .T. then the browser will not allow scripts to access the cookie.
cSameSite
If specified, it is used as the value of the cookie's SameSite attribute.

Remarks

If you want the new cookie to be sent with all requests to the server, regardless of path then you should specify "/" in the cCookiePath parameter.

Cookie headers are part of the HTTP header, so they must be sent before any content is sent to the browser. If you disable buffering of script output and attempt to use this method after you have already sent content to the browser, FoxWeb will return an error message.


Write Method

Description

The Response.Write method writes a string to the output buffer.

Syntax

Response.Write(vOutput)

Parameters

vOutput
The data being sent to the client. This parameter can be of type Character, Number, DateTime, Date, or Logical. If vOutput is not of type Character, it is automatically translated with the Server.ToString function. This value cannot contain the character combination %>. If you need to send this character combination to the browser, then you should use the escape sequence %\>.

© Aegis Group