Hardware Reference
In-Depth Information
Type the code at right.
Try It
telnet www.google.com 80
The server will respond as follows
(on Windows,use PuTTY and open a
connection to www.google.com, port
80, Connection Type: Raw):
The built-in Windows version of telnet is not very good. For
example, you won't be able to see what you type without
setting the localecho option, and the informative “Trying . . .
Connected” prompts do not appear. Use PuTTY instead ( http://
www.chiark.greenend.org.uk/~sgtatham/putty ).
!
Trying 64.233.161.147...
Connected to www.l.google.com.
Escape character is '^]'.
Type the code to the right.
8
GET /index.html HTTP/1.1
Host: www.google.com
Connection: Close
Press the Return key twice after this last
line. The server will then respond with
something like this:
HTTP/1.1 200 OK
Date: Mon, 18 Jul 2011 00:04:06 GMT
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Server: gws
Connection: Close
NOTE: If telnet doesn't close on its own, you
may need to press Ctrl-] to get to the telnet
prompt, where you can type q followed by
Enter to exit.
After the header, the next thing you'll see is a
lot of HTML that looks nowhere near as simple
as the normal Google web interface. This is the
HTML of the index page of Google. This is how browsers
and web servers talk to each other, using a text-based
protocol called the Hypertext Transport Protocol (HTTP) .
The http:// at the beginning of every web address tells
the browser to communicate using this protocol. The stuff
that precedes the HTML is the HTTP header information.
Browsers use it to learn the types of files that follow, how
the files are encoded, and more. The end user never needs
this information, but it's very useful in managing the flow of
data between client and server.
Remember the PHP time example from Chapter 1?
It should still be sitting on your own web server, at
www.example.com/time.php (replace www.example.com
with the address of your server). Try getting this
file from the command line.
Try It
Modify the PHP program
slightly, removing all the
lines that print any HTML, like the code
on the right.
<?php
/* Date page
Context: PHP
Prints the date. */
Now, telnet into your web server on
port 80 and request the file from the
command line. Don't forget to specify
the HOST in your request, as shown
earlier in the request to Google.
// get the date, and format it:
$date = date("Y-m-d h:i:s\t");
// include the date:
echo "< $date >\n";
?>
You should get a much more abbrevi-
ated response.
 
Search WWH ::




Custom Search