322
Platforms
©2000-2008 Tibbo Technology Inc.
HTTP restricts the use of some characters- you cannot freely send any code from
the ASCII table. When you use the sock.setdata and sock.send, you are "printing"
data directly to the browser. It is your program's responsibility to avoid illegal
characters and use "%xx" instead.
URL Substitution
. Actual HTML
contents received by the browser may partially be generated by your Tibbo BASIC
application. Files of other types -- plain text, graphics, etc. -- cannot include
executable code and are static in nature. These files are sent to the browser "as
is".
So, what if you need to generate such a non-HTTP file dynamically? For example,
what if you want to generate a BMP file? The answer is in using "URL substitution".
The
property allows you to do this.
The property stored a list of comma-separated file names (with extensions). When
the web server receives a request for a non-HTML file from the browser (say, "pix.
bmp"), it first tries to find this file among the HTML and resource files of your
project. Failing this, the web server looks at defined substitutions. If the requested
file is not on the list, the web server returns the "404 error".
If the file is on the list of defined substitutions, the browser looks for the file with
the same name but ".html" extension ("pix.html"). If there is no such file, the "404
error" is, again, the answer. If this HTML file exists the server outputs this file, but
makes it look like it was a file of the original type (server processes "pix.html",
brower gets "pix.bmp").
Since the actual behind-the-scenes output is done for the HTML file you can put
your own code into that file and generate content dynamically. The following
example shows how we generate the file "pix.bmp" dynamically. For this to work,
we need to set sock.urlsubstitutes="pix.bmp" somewhere in the initialization
section of the project. Here is what we have in "pix.html" file:
<?
Dim
x
As
Byte
Dim
s
As
String
romfile.open("source.bmp")
Do
x=sock.txfree
s=romfile.getdata(x)
sock.setdata(s)
sock.send
Loop
While
Len
(s)=x
?>
In this example we simply read and output the contents of another bmp file called
"source.bmp". No value is added -- we could just access that graphical file directly.
Your code, however, is free to do anything and substitution opens up the way to
create your picture on the fly, or dynamically generate the content for other
"static" files.
319
320
364