1 / 18

Fundamentals of Web Programming

Fundamentals of Web Programming. Lecture 7: HTTP & CGI. Today’s Topics. Hypertext Transfer Protocol (HTTP) Common Gateway Interface (CGI). URLs and URIs. Used interchangeably: URL : Uniform Resource Locator URI : Uniform Resource Identifier URLs can use one of many different protocols:

Download Presentation

Fundamentals of Web Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals ofWeb Programming Lecture 7: HTTP & CGI Lecture 7: HTTP and CGI

  2. Today’s Topics • Hypertext Transfer Protocol (HTTP) • Common Gateway Interface (CGI) Lecture 7: HTTP and CGI

  3. URLs and URIs • Used interchangeably: • URL: Uniform Resource Locator • URI: Uniform Resource Identifier • URLs can use one of many different protocols: • ftp://… • news://… • http://… (our focus today: http URLs) Lecture 7: HTTP and CGI

  4. Anatomy of a URL • http://host[:port][/path][?search] • Examples: • Host • http://localhost • http://www.cnn.com • Port • http://localhost:80 Lecture 7: HTTP and CGI

  5. Anatomy of a URL • Examples • Path • http://localhost/new.html • Search • http://localhost/mirror.cgi?arg=val Lecture 7: HTTP and CGI

  6. HTTP • Client-Server Communication • The Browser is the Client • The Web Site is the Server • Client Request: HTTP request • Server Response: HTTP response Lecture 7: HTTP and CGI

  7. Browser Web Server HTTP Communication 1. Extract Host Part of URL http://www.cnn.com/index.html 2. Get IP address from DNS 207.25.71.28 3. Establish TCP/IP connection to Host 4. Send HTTP Request Hello! GET /index.html 5. Wait for Response Content/type: text/html <html><body> <h1>Hello!</h1>... 6. Render Response Lecture 7: HTTP and CGI

  8. HTTP Is Stateless • A stateless protocol doesn’t remember anything from one transaction to another (all transactions are independent) • Workarounds: • Use INPUT with TYPE=HIDDEN to store state information • use cookies to store state information Lecture 7: HTTP and CGI

  9. CGI: Common Gateway Interface • Standard interface supports server programming in a variety of ways: • Unix shell scripts • PERL scripts • C, C++ programs • Java servlets • ASP • etc. Lecture 7: HTTP and CGI

  10. 7. Closes Connection Hello! CGI Program 4. Send Header 5. Send Content Content-type: text/html Browser <html><body> <h1>Hello!</h1> </body></html> 8. Display Content Web Server CGI Protocol 1. Notice URL is a program 2. Prepare the environment 3. Launch script/program 6. Exit Lecture 7: HTTP and CGI

  11. CGI Advantages • Allows dynamic control of “pages” • Examples: • counters • customized pages (user prefs) • interactions with state(server ‘remembers’ data from request to request; e.g., shopping basket) Lecture 7: HTTP and CGI

  12. CGI Pitfalls • Resource Requirements • Resource Contention • Where to Store Scripts? • Stored in one directory, managed centrally • Stored in several directories, distributed management Lecture 7: HTTP and CGI

  13. CGI Pitfalls • Portability • Yes: Perl, C, C++ • No: VBasic, Unix shell scripts • Server Independence • File paths (data) • Program location (support functions) Lecture 7: HTTP and CGI

  14. CGI Methods • GET: Information is sent directly in the URL • POST: Information is sent via STDIN stream Lecture 7: HTTP and CGI

  15. CGI Variables • REQUEST_METHOD: GET | POST • QUERY_STRING: the data sent • CONTENT_LENGTH: the amount of data • If you use a CGI support library (e.g., CGI.pm), this is taken care of automatically Lecture 7: HTTP and CGI

  16. Standard Variables • See list on p. 875 of the text • Try the mirror.cgi program on the course server Lecture 7: HTTP and CGI

  17. URL Encoding • Special chars (&, +) must be escaped • ‘&’ = %25; ‘ ’ = %20 • CONTENT_TYPE indicates the style of encoding • If you use a CGI support library, this is taken care of for you • Example: basket.cgi with GET Lecture 7: HTTP and CGI

  18. Complete Example • Simple Shopping Basket • See script basket.cgi on the course server Lecture 7: HTTP and CGI

More Related