34531

Internet Technologies
and Their Applications
home

POST and GET

Sample HTML Document

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
    <head>
        <meta http-equiv="content-type"
              content="text/html; charset=iso-8859-1">
        <title>form-test</title>
        <meta name="generator" content="BBEdit 8.0">
        <style type="text/css">
            body { text-align: center;} 
        </style> 
    </head>
    <body>
        <h1>Form-Test</h1>
        <h2>A form using the "GET" method</h2>
        <form action="http://webadmin.mathiesen.info/browsertest.xhtml"
              method="get">
            <input type="text"
                   name="name"
                   value="input your name"
                   size="30"
                   onfocus="this.value=''">
            <br>
            <input type="text"
                   name="studentnumber"
                   value="s<year><number>"
                   size="30"
                   onfocus="this.value='s'">
            <br>
            <button type="submit"
                    value="send the data">send the data</button>
            <button type="reset"
                    value="reset">reset</button>
        </form>
        <h2>A form using the "POST" method</h2>
        <form action="http://webadmin.mathiesen.info/browsertest.xhtml"
              method="post">
            <input type="text"
                   name="name"
                   value="input your name"
                   size="30"
                   onfocus="this.value=''">
            <br>
            <input type="text"
                   name="studentnumber"
                   value="s<year><number>"
                   size="30"
                   onfocus="this.value='s'">
            <br>
            <button type="submit"
                    value="send the data">send the data</button>
            <button type="reset"
                    value="reset">reset</button>
        </form>
    </body>
</html>

You can try it here (opens in new window)

The "GET" Method

Notice that the URL get's the parameters from the form appended to it.

http://webadmin.mathiesen.info/browsertest.xhtml?name=Bjarne+Mathiesen&studentnumber=s022518

GET /browsertest.xhtml?name=Bjarne+Mathiesen&studentnumber=s022518 HTTP/1.1
Host: webadmin.mathiesen.info
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; da-DK; rv:1.8b) Gecko/20050217 MultiZilla/1.8.0.1m
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://dtu.mathiesen.info/030-www/postget.html

HTTP/1.x 200 OK
Date: Wed, 28 Sep 2005 12:09:04 GMT
Server: Apache
X-Powered-By: PHP/5.0.4
Keep-Alive: timeout=30, max=1000
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html;charset=iso-8859-1

The "POST" Method

Here, the URL is 'clean' and the parameters are transmitted as part of the headers.

http://webadmin.mathiesen.info/browsertest.xhtml

POST /browsertest.xhtml HTTP/1.1
Host: webadmin.mathiesen.info
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; da-DK; rv:1.8b) Gecko/20050217 MultiZilla/1.8.0.1m
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://dtu.mathiesen.info/030-www/postget.html
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
name=Bjarne+Mathiesen&studentnumber=s022518

HTTP/1.x 200 OK
Date: Wed, 28 Sep 2005 12:14:01 GMT
Server: Apache
X-Powered-By: PHP/5.0.4
Keep-Alive: timeout=30, max=1000
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html;charset=iso-8859-1


home