Creating WAP pages with Active FoxPro Pages isn't that hard but there are some pre-requisite we have to handle...
We have to know that WAP pages have another content type than standard HTML pages. And so, we have to take care of changing the Content-Type field in the HTTP header before responding the content to any kind of WAP browser ie. mobile cell phone, SmartPhone or emulated WAP browser.
Okay, let's go...
First, the web server has to be configured to direct any WAP requests - commonly indicated with the extension .WML - to the AFP engine. Do realize this add a script mapping for .wml that points towards AFP3.DLL. In IIS open the configuration dialog on the tab "Home Directory" and with Apache HTTPd add the following line:
AddHandler afp-script .wml
Second, configure the AFP 3.0 engine itself to accept requests with file extension .wml. Open the AFP 3.0 ControlCenter, load your current configuration and choose tab "Server". Add the extension in the field "Valid file types". Otherwise AFP quits any request with an HTTP 404 error code.
After adding the extension save your configuration and re-start your AFP. *g*
Alright, that's enough configuration and we are going to process WML documents.
In order to check the HTTP header get a tool named geturl.exe from the Microsoft NT ResKit or any comparable tool like wget. Both applications are free available console tools to examine the HTTP header of the provided responses from the web server.
Personally we use wget cause it provides more parameters and functionality than geturl. Because AFP runs on Windows-only system, this article explains the next while using geturl.
Remark:
Place geturl.exe in %PATH% environment - either Windows, System32 or Command directory.
Here are the command line parameters of geturl:
C:\>geturl -?
unexpected option -?
Usage:
geturl <URL> [-h] [-d] [-v] [-p user:pass] [-o output_file] [-proxy name] [-post name file]
<URL> stands for the URL you wanna get
-h if you want the HTTP header with your document
-d if you do not want document to be included (ie
you only want the header)
-p if you wanna get a password protected document.
(suppose your user id is FOO and your password
is BAR, then you'll use "-p FOO:BAR")
Basic authentication scheme will be used.
-o by default, geturl outputs the document on stdout.
If you want a file instead, use this parameter.
-v verbose mode. This mode might prove usefull while
debugging an application that uses geturl. It send
informations of currently performed action on stderr.
-post allows to call a cgi using the 'post' method
instead of the 'get' method. This option must be followed
by the name of the parameter and a file name that will be
sent to the cgi as value for that parameter.
You can add as much -post parameters as needed.
For short fixed value parameters, you can also add them
at the end of the URL using the 'get' notation.
-proxy allows to retrieve pages through a firewall/proxy
note that the proxy will only be used if direct name
resolution fails (by default, proxy name is 'firewall').
Examples:
geturl http://www.netscape.com/jwz/index.html
geturl make
geturl http://mi6.ac.uk/index.html -p bond:james007
geturl http://make:8080/johny.cgi?boite=coucou
...
Well, that's nice. Looks well documented and usable. To check our WML responses we only need the parameters -h and -d:
-h if you want the HTTP header with your document
-d if you do not want document to be included (ie
you only want the header)
As a test I called this domain (http://www.afpfaq.de) and here's the result of geturl:
C:\>geturl -h -d http://www.afpfaq.de
HTTP/1.1 200 OK
Date: Mon, 24 Mar 2003 21:19:21 GMT
Server: Apache/2.0.44
X-Server: AFP 3.0.451 (7927-23507-41751-7927)
Expires: -1
X-Powered-By: AFP/3.0.451
Content-Length: 14364
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Language: de
As you can see the Content-Type is text/html. That's the standard value for Active FoxPro Pages. Okay, there are a lot of additional information as well. *g*
To return understandable WML pages (aka WAP pages) we have to tweak the Content-Type field of the HTTP header. So, we need a small 'correction' during creation of any .WML documents before we send them back to the browser on our visitor's mobile.
There are two possible solution:
- Inside each WML document
- Within an AFP event of our web application
Personally I prefer variant two. On the one hand I'm a very lazy programmer and try to avoid unnecessary typing of source code and on the other hand there is less chance to forget to change the content type. But we will see both solutions in detail.
Inside each WML document
<%
Response.ContentType = "text/vnd.wap.wml"
%>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="start" ontimer="#index">
<timer value="30"/>
<p align="center">
<img src="welcome.png" alt="Welcome!"/>
</p>
</card>
<card id="index" title="AFP FAQ" newcontext="true">
<p>
This is just a demo for AFP<br/>
- <% ? DATETIME() %><br/>
</p>
</card>
</wml>
Within an AFP event of our web application
Add the following lines to your webapplication (xxx.afpa.code). Best place seems to be Event_PageBefore:
Function Event_PageBefore
If Upper(JustExt(File.FullPath())) == "WML"
Response.ContentType = "text/vnd.wap.wml"
EndIf
EndFunc
Now any requests on files with .WML as extension gets the correct content type automagical.
How should the result of our cosmetic operation look like? The AFP FAQ offers a small WML document for testing purposes:
C:\>geturl -h -d http://www.afpfaq.de/i.wml
HTTP/1.1 200 OK
Date: Mon, 24 Mar 2003 21:20:55 GMT
Server: Apache/2.0.44
Last-Modified: Mon, 24 Mar 2003 21:20:44 GMT
ETag: "276a-4e-70988e25"
Accept-Ranges: bytes
Content-Length: 78
Connection: close
Content-Type: text/vnd.wap.wml
Content-Language: de
Et voilā, the Content-Type field of the HTTP header is correctly set to the specification of WML and the response should be readable on any WML browser ie. mobile cell phone
There are other WML elements like figures and source code. To get them working as well with AFP redo the above with these content types:
| Extension |
ContentType |
Type |
| .wml |
text/vnd.wap.wml |
WML document |
| .wmlc |
application/vnd.wap.wmlc |
Compiled WML document |
| .wmls |
text/vnd.wap.wmlscript |
WML script |
| .wsc |
application/vnd.wap.wmlscriptc |
Compiled WML script |
| .wbmp |
image/vnd.wap.wbmp |
Wireless Bitmap |
For further information on WML and WAP start any search engine like Google and examine the results.
Enjoy the AFP FAQ, JoKi