OUI

8.12 Why does a normal HTTP 302 redirect not work with WAP?

The truth is that it does. The crucial detail is the server side script language, or rather the interaction between the server side script language and the web server.

The so called 302 Found HTTP response basically means that the web server tells the user agent that the resource may be found elsewhere, temporarily. All web servers I have tested so far add a Content-type: to the response even if there is no content. By default the Content-type: is in normal circumstances text/html.

Actually, the HTTP specifications on "302 Found" say that the web server, unless the request method was HEAD and not GET, should also send a body containing a short message for the (human) user saying that the location has changed. In WML's case, the short message must obviously be a full WML deck with one card. If the gateway/browser fully supports a redirect, the message will not be shown. If it doesn't, the user will have to manually follow the link to the new location. This is crucial if your script may output any characters, either on purpose or by mistake. ASP is famous for outputting whitespaces where there should be none. This doesn't cause a problem for a HTML browser, but will certainly do so for a WML browser.

Note that none of the examples below contain a body - just the header.

Thanks to the following code examples have been tested and found to work on Apache and Microsoft Internet Information Server. If you use another web server or another script language, you should be able to convert these rather simple script snippets. And the keyword is simple. No need to tell the web server to generate a full HTTP header unless you need to. Most web servers will complement the header so that the user agent understands it. This is just to override what's absolutely required as a minimum.

All code examples are available for testing online. If they work, you will be redirected to which generates a WML deck with a card that displays all HTTP headers.

PHP code example which can be tested at :

<?
  header("Location: http://...");
  header("Content-type: text/vnd.wap.wml";
?>

Perl code example which can be tested at http://...:

print "Location: http://...";
print "Content-type: text/vnd.wap.wml\n";

Adds that with Perl you can use the No-Parsed-headers option which will produce the complete HTTP response so that the web server does not have to:

#!/usr/local/bin/perl
use CGI qw(:standard);
print redirect(-uri=>'http://...',-nph=>1);

This requires informing the web server that the script is a nph script (on Unix you rename the script to start with nph- on NT IIS figures this out by itself )

ASP code example which can be tested at http://... (note different URL):

<%
  Response.Redirect("http://...")
  Response.ContentType = "text/vnd.wap.wml"
  Response.Flush
  Response.End
%>
[ Main ]   [ 08 - Troubleshooting ]