CM40212 HTTP/SMTP Primer Terminal access The examples are best run from a unix (linux) machine: • From the windows desktop open Putty • Connect to lcpu.bath.ac.uk • Log in with your BUCS username and password. Simple HTTP 1.0 get We connect to the bath web server (www.bath.ac.uk) which has the IP 138.38.0.49 To get the IP of a server run (user input is in bold): > host www.bath.ac.uk www.bath.ac.uk has address 138.38.0.49 The following gets the bath home page ( http://www.bath.ac.uk/ ) > telnet 138.38.0.49 80 GET / HTTP/1.0 HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 09:57:02 GMT Server: Apache/2.2.20 (Unix) Accept-Ranges: bytes Connection: close Content-Type: text/html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Internal homepage | University of Bath</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="DC.Creator" content="web-ed@bath.ac.uk" /> ... 1
Simple HTTP/1.1 get with host The following gets the same page in HTTP/1.0 referring to the specied host (required). > telnet 138.38.0.49 80 GET / HTTP/1.1 Host: www.bath.ac.uk HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 15:00:54 GMT Server: Apache/2.2.20 (Unix) Vary: Host Accept-Ranges: bytes Transfer-Encoding: chunked Content-Type: text/html 11f2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Internal homepage | University of Bath</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="DC.Creator" content="web-ed@bath.ac.uk" /> ... 0 Simple HTTP/1.1 get of different virtual host > telnet 138.38.0.49 80 GET / HTTP/1.1 Host: www.teambath.com HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 15:06:42 GMT Server: Apache/2.2.20 (Unix) X-Powered-By: PHP/5.3.8 X-Pingback: http://www.teambath.com/xmlrpc.php Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 203c <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Team Bath</title> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="language" content="english" /> ... 0 2
Simple HTTP POST We post data to http://people.bath.ac.uk/masjap/post.php > telnet 138.38.32.6 80 POST /masjap/post.php HTTP/1.1 Host: people.bath.ac.uk Content-Type: application/x-www-form-urlencoded Content-Length: 17 var1=foo&var2=bar HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 15:12:40 GMT Server: Boa/0.94.14rc21 Accept-Ranges: bytes X-Powered-By: PHP/5.3.5 Content-type: text/html X-Cache: MISS from people.bath.ac.uk Transfer-Encoding: chunked 67 <html> <body> Post variables <pre> Array ( [var1] => foo [var2] => bar ) </pre> </body> </html> 0 Sending Cookies We send some cookies to http://people.bath.ac.uk/masjap/cookie.php and get some back. > telnet people.bath.ac.uk 80 GET /masjap/cookie.php HTTP/1.1 Host: people.bath.ac.uk Cookie: cookie1=value1;cookie2=value2 HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 15:57:10 GMT Server: Boa/0.94.14rc21 Accept-Ranges: bytes X-Powered-By: PHP/5.3.5 Set-Cookie: cookiekey1=Some+text Set-Cookie: last_visit=Thu%2C+13+Oct+2011+16%3A57%3A21+%2B0100 Content-type: text/html X-Cache: MISS from people.bath.ac.uk Transfer-Encoding: chunked 78 <html> <body> I received cookies: <pre> Array ( [cookie1] => value1 [cookie2] => value2 ) </pre> </body> </html> 0 3
Failed authentication The URL http://people.bath.ac.uk/masjap/auth.php requires authentication > telnet people.bath.ac.uk 80 GET /masjap/auth.php HTTP/1.1 Host: people.bath.ac.uk TTP/1.1 401 Unauthorized Date: Thu, 13 Oct 2011 16:04:53 GMT X-Powered-By: PHP/5.3.5 WWW-Authenticate: Basic realm="Authenticated Page" Content-type: text/html X-Cache: MISS from people.bath.ac.uk Transfer-Encoding: chunked 42 This is the body of the 401 response, mostly people don’t see this 0 Successful authentication We post to the same URL, this time including a base-64 encoded username and password. For HTTP Basic Auth the encoding scheme is Base64(username : password). The page accepts any combination of username and passsword. Use an online tool like http://www.motobit.com/util/base64-decoder-encoder. asp to encode the authentication data, or use the unix command line tool base64 . > telnet people.bath.ac.uk 80 GET /masjap/auth.php HTTP/1.1 Host: people.bath.ac.uk Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== HTTP/1.1 200 OK Date: Thu, 13 Oct 2011 16:08:39 GMT Server: Boa/0.94.14rc21 Accept-Ranges: bytes X-Powered-By: PHP/5.3.5 Content-type: text/html X-Cache: MISS from people.bath.ac.uk Transfer-Encoding: chunked 65 <html> <body> hello <b>Aladdin</b> you entered the password:<b>open sesame</b><br/> </body> </html> 0 4
Simple SMTP session The following session sends mail to me from me, note that the From:, and Date header are required to send a mail. Use http://www.sanctumvoid.net/jsexamples/rfc822datetime/rfc822datetime. html to get the RFC822 date time. > telnet mx.bath.ac.uk 25 220-mx.bath.ac.uk 220-Greetings from the University of Bath. 220-I’m pleased to meet you. 220 mansell.bath.ac.uk SMTP server ready HELO jap-lap3.cs.bath.ac.uk 250 mansell.bath.ac.uk Hello fire.cs.bath.ac.uk [138.38.108.253] MAIL From: <j.a.padget@bath.ac.uk> 250 OK RCPT To: <j.a.padget@bath.ac.uk> 250 Accepted DATA 354 Enter message, ending with "." on a line by itself From: Julian Padget <j.a.padget@bath.ac.uk> To: Julian Padget <j.a.padget@bath.ac.uk> Subject: Test email Date: Thu, 13 Oct 2011 17:13:41 +0100 I think we have met somewhere before . 250 OK id=1RENtY-0003Yq-5F QUIT 221 mansell.bath.ac.uk closing connection 5
Recommend
More recommend