8.6 I can't get POST to work! What's wrong?

There have been many rumours that POSTed variables in many cases get lost, especially from the Nokia 7110. As far as we know, there are no versions of the Nokia 7110 that have problems with using POSTed variables. The problem lies in the gateway(s) and/or the receiving end, i.e. the script or whatever is reading the data from the client side.

Tests have shown that the Nokia SDK 2.18 have problems using POSTed variables when using the built-in gateway (the gray window on the right side of the screen). Even when the method is set to "post" the server side reads the posting as a request, i.e. as a GET. This can be tested by using the simple WML deck which is also available from the WAP/WML FAQ Demos Section at DEMO. The Nokia SDK will also usually corrupt the URL for the POST. In some cases the last character of the URL will be removed.

The Post Test deck will simply post two variables called "var1" and "var2" to a script that will display the contents of the variables and the full HTTP header contents. If you cannot see the correct contents in the variables, something went wrong. Check the HTTP header for the string application/x-www-form-urlencoded. (Note! You need to input something into the variables to actually see any content of course)

The way to solve the problem with the Nokia SDK 2.18, is to configure it to use any of the publicly available WAP gateways. A list is available here. I recommend using the wapHQ gateway.

In other cases where POSTing does not seem to work, the problem might be with how the HTTP headers are parsed on the server side. Script languages such as ASP and Java, and also CGI's typically look for an exact match of the string application/x-www-form-urlencoded in the HTTP header. In some cases the string might have additional data appended, such as charset="utf8" which describes which character set the POSTed data is in. Since the server side does an exact match, it will not see the HTTP header, and the POSTed variables are lost.

Note that this is not the browsers fault. Adding the character set info is allowed in HTTP. The script language is the guilty party.

To check if this is a problem with the browser/gateway combination you are using, the same Post Test deck as above can be used. Again look for the string application/x-www-form-urlencoded in the output, and check if there is any additional characters appended to the end of it. If there is, chances are that your server side application does not see the header.

The solution to this problem is more difficult, and it varies between the different script languages, and in the case where a CGI is used, you'll need access to the source code. In short, the solution is to read the HTTP header manually, i.e. not using the prewritten commands of your script language to do it.

If you discover this problem with your browser/gateway combination, please mail with a description of which browser and gateway is being used. If you in addition already have a solution, we'll present it in this FAQ.

And here is one solution to the problem with ASP submitted. It shows how to grab the data that was sent as a POSTing from the browser as binary data. You'll need to parse the binary data to find the variables you need.

Dim lngToalByteCount
Dim vntRequestData
IngTotalByteCount = Request.TotalBytes
vntRequestData = Request.BinaryRead(lngTotalByteCount)

Turned into actual code, it would look something like this which kindly submitted.

<%@ Language=VBScript %>
  Dim Temp, i, sPost, sWMLDeck
  'Converts the binary data to a string.
  For i = 1 To Request.TotalBytes
    Temp = Request.BinaryRead(1)
    sPost = sPost & Chr(AscB(Temp))
  'Parses out the values of the POSTED variables (in this
  'example myvar1 and myvar2).
  Dim sVar1, sVar2
  sVar1 = getVar("myvar1", sPost)
  sVar2 = getVar("myvar2", sPost)
  'Writes the WML Deck displaying the POSTED Variables
  sWMLDeck = "<?xml version=""1.0""?>" & vbCrLf
  sWMLDeck = sWMLDeck & "<!DOCTYPE wml PUBLIC ""-//WAPFORUM//DTD WML 1.1//EN"" "
  sWMLDeck = sWMLDeck & """http://...."">" & vbCrLf
  sWMLDeck = sWMLDeck & vbCrLf & "<wml>" & vbCrLf & vbTab
  sWMLDeck = sWMLDeck & "<card id=""main"" title=""POST TEST"">" & vbCrLf
  sWMLDeck = sWMLDeck & vbTab & vbTab & "<p>" & vbCrLf
  sWMLDeck = sWMLDeck & vbTab & vbTab & vbTab & "myVar1: " & sVar1 & "<br/>" & vbCrLf
  sWMLDeck = sWMLDeck & vbTab & vbTab & vbTab & "myVar2: " & sVar2 & vbCrLf
  sWMLDeck = sWMLDeck & vbTab & vbTab & "</p>" & vbCrLf & vbTab
  sWMLDeck = sWMLDeck & "</card>" & vbCrLf & ">/wml>"
  Response.ContentType = "text/vnd.wap.wml"
  'Quick function for picking out the values of the POSTed variables.
  'sKey is the variable name, sRaw is the POST string.
  Private Function getVar(sKey, sRaw)
    Dim sRetVal
    If InStr(sRaw, sKey) Then
      sRetVal = Mid(sRaw, InStr(sRaw, sKey) + Len(sKey) + 1)
      If InStr(sRetVal, "&") Then
        sRetVal = Mid(sRetVal, 1, InStr(sRetVal, "&") - 1)
      End If
    End If
    getVar = sRetVal
  End Function
[ Main ]   [ 08 - Troubleshooting ]