190 likes | 315 Vues
This lesson explores the fundamental differences between HTTP (Hypertext Transfer Protocol) and HTML (Hypertext Markup Language). HTTP governs the communication between web clients and servers, defining how requests and responses are structured. We delve into HTML tags that shape web document appearance and how they interact with HTTP requests, including GET and POST methods. Additionally, we discuss server responses, status codes, and the role of cookies in maintaining session state. This knowledge is essential for anyone interested in web development and design.
E N D
Operating Systems Lesson 12
HTTP vs HTML • HTML: hypertext markup language • Definitions of tags that are added to Web documents to control their appearance • HTTP: hypertext transfer protocol • The rules governing the conversation between a Web client and a Web server
HTML <html><body> <h1>My First Heading</h1> <p>My first paragraph.</p> <img src="hackanm.gif" width="45“ height="45" /></body> </html>
HTTP • HTPP is a text-based protocol: uses text to represent its control messages • HTTP is a asymmetric: there are a client and server • HTTP is stateless: a session consist of single request/response pair • HTTP servers usually listen to incoming TCP connection on port 80
HTTP request format Cr=‘\r’ lf=‘\n’
Passing Parameters to the Web Server • HTML: • <form name="input" action=“form.asp" method="get"> <input type="text" name="user" /> <input type="submit" value="Submit" /></form> • Browser: • HTTP Request: • GET form.asp?user=tom HTTP/1.1 • Common Gateway Interface(CGI) • Standard for passing query parameters to the scripts/applications • Parameters(query string) via environment variable
Some HTTP Request Methods • GET: retrieve information identified by the URL. • HEAD: retrieve meta-information about the URL • POST: send information to a URL and retrieve result. HTTP
Response Status Line HTTP-Version Status-Code Message • Status Code is 3 digit number (for computers) • 1xx Informational • 2xx Success • 3xx Redirection • 4xx Client Error • 5xx Server Error • Message is text (for humans) HTTP
Example Status Lines HTTP/1.0 200 OK HTTP/1.0 301 Moved Permanently HTTP 1/0 304 Not Modified HTTP/1.0 400 Bad Request HTTP/1.0 500 Internal Server Error HTTP
Some Request Headers • User-Agent • Identification of the browser software • Accept • MIME types that browser is ready to accept • If-Modified-Since • Date of cached reqource
Some Response Headers • Content-Type: • Type of the returned content • MIME identifier • text/html, video/mpeg • Content-Length • Size of the content in bytes • Last-Modified • Date of last modification
Persistent Connection • HTTP 1.0 TCP connection is closed after each request/response exchange • HTTP 1.1 allows keeping TCP connection for next request/response • Browser: request header • Connection:Keep-Alive • Default in HTTP 1.1
Cookies • Need a state over HTTP • Cookie Mechanism • Server instructs browser to keep a named value and send it back to the server along with next request • Cookie Expiration Policy • Session cookie: forget cookie after browser is closed • Expiration time: forget after prescribed time
Cookie Headers • Server (Response Header) • Set-Cookie: name_a=value • Client (request Header) • Cookie: name_a=value; name_b=value