contents   index   previous   next



TrapFileDataEx

 

This is an enhanced version of the TrapFileData method.

 

If TrapFileEnable is set to TRUE, then FileRequest event will fire when a request is received by WebX. The developer can choose to inspect the name of the requested file and query string and also bypass the subsequent search for a file and return data directly to the client. The TrapFileDataEx is used to return the data the application is to send to the client.

 

In addition to the parameters that can be passed back with the TrapFileData method, TrapFileDataEx also supports overriding the Status Code field and added additional header fields.

 

For example:

 

Private Sub WebX1_FileRequest(Index As Integer, FileName As String, UserAuthentication As String)

   If FileName = "/index.wml" Then

        sHeader = ""

        sHeader = sHeader & "Pragma: no-cache" & vbCrLf

        sHeader = sHeader & "Cache-control: no-cache" & vbCrLf

        sHeader = sHeader & "Expires: Mon, 01 Jan 1990 12:00:00 GMT" & vbCrLf

        sHeader = sHeader & "Location: test2.asp" & vbCrLf

        WebX1.TrapFileDataEX Index, "WML Index Page: Hello World!", _

                                       False, "text/vnd wap.wml", "222", sHeader

 

   Else If FileName = "/index.html" Then

        WebX1.TrapFileData Index, "HTML Index Page: Hello World!", False

 

   End If

End Sub

 

In the above example, you can see some of the extra control possible with the TrapFileDataEx method. Even though we are returning a valid page, which would normally have a status code of 200, we are sending back Status Code 302 (Moved Temporarily) and setting other header so proxy servers and browsers do not cache this page.

 

Non-Standard and custom headers fields could also be specified if desired, the only requirement being that they are separated by a vbCrLf if more than one field is specified. This may be very useful if serving data to custom client applications. In addition, keep in mind that custom header fields should still be in the format “HeaderField: MyData” & vbCrLf to maintain compatibility with web browsers.

 

 

Parameter

Type

Description

Index

Integer

Used to link the returned data to the requesting connection.

Data

String

Contains the data to be sent to the requesting client.

[WebXProcess]

Boolean

Optional. Default Value = TRUE. If TRUE, the application will not send any data to the client and WebX will look for the file (HTML or binary) to be sent. If FALSE, the application will provide WebX the data to be sent to the client in Data.

[ContentType]

String

Optional. Default Value = "text/html". This is the Content Type (MIME) that is sent to the client.

[StatusCode]

String

The Status Code to be sent to the client. This overrides the Status Code that WebX Server would send back.

[HeaderField]

String

Header Field(s) that will be sent to the client. Multiple fields must be separated by CrLf (i.e. vbCrLf).

 

Version