|
Fall Semester 2002 |
Place this script in your cgi-bin:
#!/usr/bin/perl
if ($ENV{REQUEST_METHOD} eq 'GET') {
$in = $ENV{QUERY_STRING};
} else {
read(STDIN, $in, $ENV{CONTENT_LENGTH});
}
print "Content-type: text/html\n\n($in)\n";
Part A:
Connect to your server using telnet from tucotuco this way:
Explain the process and the result.tucotuco.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. GET /cgi-bin/eOne HTTP/1.0 HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 18:40:42 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html () Connection closed by foreign host. tucotuco.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. GET /cgi-bin/eOne?hello HTTP/1.0 HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 18:40:59 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html (hello) Connection closed by foreign host. tucotuco.cs.indiana.edu%
Part B:
Now connect again but do it this way:
tucotuco.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. POST /cgi-bin/eOne HTTP/1.0 HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 18:48:18 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html () Connection closed by foreign host. tucotuco.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. POST /cgi-bin/eOne HTTP/1.0 Content-length: 5 heLLo HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 18:48:40 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html (heLLo) Connection closed by foreign host. tucotuco.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. POST /cgi-bin/eOne HTTP/1.0 Content-length: 5 abcdefghij HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 18:49:34 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html (abcde) Connection closed by foreign host. tucotuco.cs.indiana.edu%
Explain the process and the result, compare with Part A.
Experiment Two.
Add eTwo to your cgi-bin:
#!/usr/bin/perl
if ($ENV{REQUEST_METHOD} eq 'GET') {
$in = $ENV{QUERY_STRING};
} else {
read(STDIN, $in, $ENV{CONTENT_LENGTH});
}
print "Content-type: text/html\n\n";
@in = split(/&/, $in);
foreach $e (@in) {
print $e, "\n";
}
Part A:
Connect from tucotuco this way:
frilled.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. GET /cgi-bin/eTwo?a=b&c=d a=b c=d Connection closed by foreign host. frilled.cs.indiana.edu% telnet burrowww 10000 Trying 129.79.245.98... Connected to burrowww.cs.indiana.edu. Escape character is '^]'. POST /cgi-bin/eTwo HTTP/1.0 Content-length: 7 a=b&c=d HTTP/1.1 200 OK Date: Sat, 14 Oct 2000 19:39:45 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/html a=b c=d Connection closed by foreign host. frilled.cs.indiana.edu%
Explain the process and the result.
Part B:
Create the following file, and add it as eTwo.html in your htdocs.
<html> <body bgcolor=white> <form method=POST action="/cgi-bin/eTwo"> <input type=text name=userInput> <p> <input type=submit> </form> </body> </html>
Then enter
in the text field and pressa=b&c=d
Submit. Explain the process and the result, and the relationship with Part A (if any).
What changes (if anything) if we replace POST by GET in the method attribute of the
<form> tag.
Experiment Three
Part A:
Add eThree.html (below) to your htdocs.
<html>
<body bgcolor=white>
<form method="POST" action="/cgi-bin/eTwo">
<input type=text name="a">
<input type=text name="c">
<input type="submit" value="Proceed">
</form>
</body>
</html>
Bring it up in your browser, type b in the first field, and d in the second. Then push the submit button.
Explain the process and the result. What relationship does this experiment have with any of the previous experiments?
Part B:
Now add eThree to your cgi-bin:
#!/usr/bin/perl
if ($ENV{REQUEST_METHOD} eq 'GET') {
$in = $ENV{QUERY_STRING};
} else {
read(STDIN, $in, $ENV{CONTENT_LENGTH});
}
print "Content-type: text/html\n\n";
@in = split(/&/, $in);
foreach $e (@in) {
($name, $value) = split(/=/, $e);
$name =~ s/%(..)/chr(hex($1))/ge;
$value =~ s/%(..)/chr(hex($1))/ge;
print $name, "=(", $value, ")";
}
Call it with
Try to anticipate the result (remember Part B from the previous experiment) and explain it.http://burrowww.cs.indiana.edu:100xx/cgi-bin/eThree?userInput=a%3Db%26c%3Dd
A348/A548