Frequently
Asked
Questions


Poll

Which Web server are you using with Active FoxPro Pages?
 


Navigation

Active FoxPro Pages FAQ
AFP 2.x
AFP in general
First steps
News
Plugins
Resources
Samples
Votes
Web server
FAQuarium
Glossary
Plugins
Server
Sidebar
Site Navigation Bar
Top Articles


Your Location

Germany


Partner Sites

- Microsoft Community Guide -
- AFPBB Boost your Board -
- AFP-Community -
- MiDeK - Internet Publishing -
- VfpNetwork.Com -
- MSDN VFP -
- CoDe Magazine -
- Golo Haas -


Advertisement

Imprint

Microsoft CLIP member

 
  [45] How to respond WAP pages with AFP?
Rate this page Print Office Email Discuss
1864 requests - last updated Mittwoch, 10.03.2004

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

All text is available under the terms of the
GNU Free Documentation License.

User contributed notesAdd a note
wget on WAP page instead of HTML
by JoKi - 03/16/2004 01:55:54
Sorry, here's the correct sample:

~ > wget -d --delete-after http://www.afpfaq.de/i.wml
DEBUG output created by Wget 1.6 on linux.

parseurl ("http://www.afpfaq.de/i.wml" -> host www.afpfaq.de -> opath i.wml -> dir -> file i.wml -> ndir
newpath: /i.wml
--01:50:13-- http://www.afpfaq.de/i.wml
=> 'i.wml'
Verbindungsaufbau zu www.afpfaq.de:80... Created fd 3.
verbunden!
---request begin---
GET /i.wml HTTP/1.0
User-Agent: Wget/1.6
Host: www.afpfaq.de
Accept: */*

---request end---
HTTP Anforderung gesendet, warte auf Antwort... HTTP/1.1 200 O
Date: Tue, 16 Mar 2004 00:53:45 GMT
Server: Apache/2.0.48
X-Server: AFP 3.0.526 (6399-48173-39990)
Expires: Wed, 17 Mar 2004 00:52:36 GMT
Set-Cookie: afpfaqsid=61945014485621245709526663348561366659861915; path=/
Content-Length: 460
Connection: close
Content-Type: text/vnd.wap.wml
Content-Language: de


Länge: 460 text/vnd.wap.wml

0K -> 100%

Closing fd 3
01:50:14 (74.87 KB/s) - 'i.wml' saved 460/460

Removing file due to --delete-after in main():
Entferne »i.wml«.


Actually setting the correct content type is the key to realize WML pages on mobiles.

Enjoy the AFP FAQ, JoKi
Using wget instead of geturl
by JoKi - 03/16/2004 01:48:19
As mentioned in the article it's also possible to use wget to examine the HTTP headers.

Here's a sample how to do this:

~ > wget -d --delete-after http://www.afpfaq.de
DEBUG output created by Wget 1.6 on linux.

parseurl ("http://www.afpfaq.de" -> host www.afpfaq.de -> opath -> dir -> file -> ndir
newpath: /
--01:41:49-- http://www.afpfaq.de/
=> 'index.html'
Verbindungsaufbau zu www.afpfaq.de:80... Created fd 3.
verbunden!
---request begin---
GET / HTTP/1.0
User-Agent: Wget/1.6
Host: www.afpfaq.de
Accept: */*

---request end---
HTTP Anforderung gesendet, warte auf Antwort... HTTP/1.1 200 O
Date: Tue, 16 Mar 2004 00:45:20 GMT
Server: Apache/2.0.48
X-Server: AFP 3.0.526 (6399-48173-39990)
Expires: Wed, 17 Mar 2004 00:45:20 GMT
X-Powered-By: AFP/3.0.526
Set-Cookie: afpfaqsid=61868876707662199342846664791030266328360196; path=/
Set-Cookie: afpfaqgui=en.default; expires=Sun, 12-Sep-2004 00:00:00 GMT; path=/
Content-Length: 61429
Last-Modified: Tue, 16 Mar 2004 00:45:21 GMT
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Language: de


Länge: 61,429 text/html

0K -> .......... .......... .......... .......... .......... 83%
50K -> ......... 100%

Closing fd 3
01:41:50 (81.18 KB/s) - 'index.html' saved 61429/61429<br><br>Removing file due to --delete-after in main():<br>Entferne &raquo;index.html&laquo;.<br>


Actually the debug messages are way more informative than with geturl. And that's why I prefer wget...

Regards, JoKi
Copyright © 2002-2005 AFP FAQ. All rights reserved. Please send any irritations on this Web site to our Webmaster. Validate HTML