The HTTP Protocol HTTP, Requests, Responses, Forms, MIME, Caching, Redirects SoftUni Team Technical Trainers Software University

Slides:



Advertisements
Similar presentations
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Advertisements

World Wide Web Basics Original version by Carolyn Watters (Dalhousie U. Computer Science)
HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
HTTP – HyperText Transfer Protocol
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Know how HTTP accesses data on the WWW Objectives.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
Web Architecture Dr. Frank McCown Intro to Web Science Harding University This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike.
COMP3016 Web Technologies Introduction and Discussion What is the Web?
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
HTTP Protocol Specification
Network Applications Outline Simple Mail Transfer Protocol
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
HTTP, AJAX and REST How HTTP and Web Services Work? SoftUni Team Technical Trainers Software University
Copyright (c) 2010, Dr. Kuanchin Chen1 The Client-Server Architecture of the WWW Dr. Kuanchin Chen.
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
WWW, HTTP, GET, POST, Cookies Svetlin Nakov Telerik Corporation
World Wide Web (WWW) A Distributed Document- Based System Group E Ricky Tong (D-A0-1611) Eddy Leong (D-A0-1623) Dick Lei (D-A0-1658)
CS 6401 The World Wide Web Outline Background Structure Protocols.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
Form Data Encoding GET – URL encoded POST – URL encoded
Part 2 – WWW and HTTP Nikolay Kostov Telerik Corporation
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting HTTP.
Web Technologies Lecture 1 The Internet and HTTP.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/7/10.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
EE 122: Lecture 21 (HyperText Transfer Protocol - HTTP) Ion Stoica Nov 20, 2001 (*)
CS 6401 The World Wide Web Outline Background Structure Protocols.
RESTful Web Services What is RESTful?
Working with Forms in PHP HTTP GET / POST, Validation, Escaping, Input Types, Submitting Arrays, URL Redirecting, PHP Superglobals Svetlin Nakov Technical.
Overview of Servlets and JSP
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
INTRODUCTION Dr Mohd Soperi Mohd Zahid Semester /16.
Web Programming Week 1 Old Dominion University Department of Computer Science CS 418/518 Fall 2007 Michael L. Nelson 8/27/07.
First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University
DOM, jQuery, AJAX, REST Using Kinvey as JS Back-End
HTML Forms, HTTP Request & HTTP Response
HTTP – An overview.
Hypertext Transfer Protocol
Web Technologies HTTP, Servers, Clients SoftUni Team
HTTP, RESTful Web Services, HTTP and REST Tools: Postman, Fiddler
Hypertext Transfer Protocol
HTTP Hypertext Transfer Protocol
CSCI-351 Data communication and Networks
Presentation transcript:

The HTTP Protocol HTTP, Requests, Responses, Forms, MIME, Caching, Redirects SoftUni Team Technical Trainers Software University

Table of Contents 1.HTTP Overview, HTML Forms, GET, POST, Action  WWW, URL, Web Servers, Web Browsers  MIME and Media Types  HTML Forms, GET, POST and Encryption Types  HTTP Requests, Headers, Responses, Response Codes  Caching: cache-control, ETag,... 2.Uploading Files through HTTP POST 3.Downloading Files: Content-Type and Content-Disposition 2

World Wide Web What is WWW?

4 World Wide Web  WWW = World Wide Web = Web != Internet  Internet is a global system of interconnected computer networks  WWW is one of the services running in these networks  Global distributed information system in Internet (like , DNS,...)  Consists of set of resources (documents, images and others)  Located at different Internet servers, identified by URL  Accessed through standard protocols (like HTTP, HTTPS, FTP) by URL  Web servers  Web servers provide Web content through the HTTP protocol  Web browsers  Web browsers access the Web content and display it What is World Wide Web (WWW)?

5  The HTTP protocol is fundamental for WWW  WWW structural components  Internet – provides data transfer channels over the TCP and HTTP  Web servers (Apache, IIS, Tomcat, Nginx, GWS, etc.) – serve HTTP  Clients (Web browsers) – download and display HTTP resources  WWW semantic components  Hyper Text Transfer Protocol (HTTP) and other protocols  Uniform Resource Locator (URL), Uniform Resource Identifiers (URI)  Hyper Text Markup Language (HTML), Cascading Stylesheets (CSS) WWW Components

The Structure of URLs Uniform Resource Locator

7  URL is a formatted string, consisting of:  Protocol for communicating ( http, ftp, https...) – HTTP in most cases  Host or IP address ( gmail.com, , web )  Port (the default port is 80) – a number in range [0…65535]  Path ( /forum, /path/ index.php )  Query string ( ?id=27&lang=en )  Fragment ( #lectures ) – used on the client to navigate to some section Uniform Resource Locator (URL) Protocol HostPortPathQuery String Fragment

8  URLs are encoded according RFC 1738 :  Safe URL characters: [0-9a-zA-Z], $, -, _,., +, *, ', (, ),,, !  All other characters are escaped by:  Space is encoded as " + " or " %20 "  Example:  URL-encoded string: URL Encoding %[character hex code] CharURL Encoding Encoding space%20 щ%D1%89 "%22 #%23 $%24 %25 &%26 %D0%9D%D0%B0%D0%BA%D0%BE%D0%B2-%E7%88%B1-SoftUni Наков- 爱 -SoftUni

9  Some valid URLs:  Some invalid URLs: Valid and Invalid URLs – Examples 8&rlz=1T4GGLL_enBG369BG369&q=http+get+vs+post D1%80%D0%BD%D0%B0_%D0%B0%D0%BA%D0%B0%D0%B4%D0%B5%D0%BC%D0%B8%D1%8F Should be: ?q=C%23+.NET+4.0 Should be: ?q=%D0%B1 %D0%B8%D1%80%D0%B0

10  Use urlencode(string) / urldecode(string) : URL Encoding / Decoding in PHP $text = "Some text / някакъв текст"; $urlEncodedText = urlencode($text); echo $urlEncodedText; Some+text+%2F+%D0%BD%D1%8F%D0%BA%D0%B0%D0%BA%D1%8A%D0%B2+ %D1%82%D0%B5%D0%BA%D1%81%D1%82 $decodedText = urldecode($urlEncodedText); echo $decodedText; Some text / някакъв текст

MIME and Media Types Multi-Purpose Internet Mail Extensions

12  MIME == Multi-Purpose Internet Mail Extensions MIME  Internet standard for encoding resources  Originally developed for attachments  Used in many Internet protocols like HTTP and SMTP  MIME defines several concepts  Content-Type, e.g. text/html, image/gif, application/pdf  Content charset, e.g. utf-8, ascii, windows-1251  Content-Disposition, e.g. attachment; filename=logo.jpg  Multipart messages (multiple resources in a single document) What is MIME?

13 MIME Type / Subtype Description application/jsonJSON data image/pngPNG image image/gifGIF image text/htmlHTML text/plainText text/xmlXML video/mp4MP4 video application/pdfPDF document Common MIME Media Types

How Browsers Open a Web Page? DNS Resolve, Connect, HTTP Request, …

15  How browsers open a URL like 1. Resolve the host name ( through the DNS systemwww.w3.org 2. Open a TCP connection to the Web server ( , port 80) 3. Make a HTTP GET request for the requested page: /standards/ 4. Retrieve the HTTP response, typically a HTML document 5. Parse the HTML and extract the related CSS, JavaScript and images 6. Make subsequent HTTP GET requests to load the CSS, JS and images 7. Render the Web page in the browser (visualize the HTML and CSS) Opening a Web Page: Step by Step

Opening a Web Page through the Console with Telnet Live Demo

HTML Forms and HTTP GET, POST, Action, Enc-Type, …

 The URL query string holds the HTTP request parameters  Typically used in GET requests The URL Query String

Query String in PHP  A query string is the part of a URL following a question mark ( ? )  Commonly used in searches and dynamic pages  Accessed in PHP through $_SERVER['QUERY_STRING'] <form> </form><?php echo $_SERVER['QUERY_STRING']; echo $_SERVER['QUERY_STRING'];?>

20  HTTP GET  Retrieves data from the client HTTP request URL  In PHP the form data accessed through $_GET ['variable']  The data sent by GET method can be accessed through $_SERVER['QUERY_STRING'] GET Request Method …</form>

21 GET Request Method – Example Name: Name: Age: Age: </form> <?php // Check the keys "name" or "age" exist if (isset($_GET["name"]) || isset($_GET["age"])) { echo "Welcome ". htmlspecialchars($_GET['name']). ". "; echo "Welcome ". htmlspecialchars($_GET['name']). ". "; echo "You are ". htmlspecialchars($_GET['age']). " years old."; echo "You are ". htmlspecialchars($_GET['age']). " years old.";}?>

22  The POST method transfers data in the HTTP body  Not appended to the query string  The posted data is stored in $_POST associative array  Using htps:// you can protect your posted data with SSL  POST can send text and binary data, e.g. upload files POST Request Method …</form>

23 POST Request Method – Example Name: Name: Age: Age: </form> <?php // Check the keys "name" or "age" exist if (isset($_POST["name"]) || isset($_POST["age"])) { echo "Welcome ". htmlspecialchars($_POST['name']). ". "; echo "Welcome ". htmlspecialchars($_POST['name']). ". "; echo "You are ". htmlspecialchars($_POST['age']). " years old."; echo "You are ". htmlspecialchars($_POST['age']). " years old.";}?>

HTML Forms: GET vs. POST Live Demo

25  HTML forms can be submitted in two formats:  application/x-www-form-urlencoded  Form fields are encoded like a URL query string, e.g. lang=en&p=12  File uploads are not supported  multipart/form-data  Each form fields is posted with headers + name + value  A special boundary identifier is used to separate between fields  Supports file upload Form Encryption Type

26 URL Encoded Form Data – Example Name: Name: Age: Age: </form> POST /index.php HTTP/1.1 Host: localhost:5555 Content-Type: application/x-www-form-urlencoded name=Maria+Smith&age=19

27 Multi-Part Form Data: Sample Form <form method="post" enctype="multipart/form-data" action="api/upload"> action="api/upload"> Name: Name: File: File: </form>

28 Multi-Part Form Data: Sample POST Request POST HTTP/1.1 Content-Type: multipart/form-data; boundary=pmVO5c0aBS --pmVO5c0aBS Content-Disposition: form-data; name="name" My CV --pmVO5c0aBS Content-Disposition: form-data; name="attachment"; filename="CV.pdf" Content-Type: application/pdf %PDF-1.5%µµµµ (… more binary data comes here …) --pmVO5c0aBS--

Form URL Encoded vs. Multipart Form Data Live Demo

The HTTP Protocol How HTTP Works?

31  HTTP == Hyper Text Transfer Protocol  Client-server protocol for transferring Web resources (HTML files, images, styles, scripts, data, etc.)  The widespread protocol for Internet communication today  Request-response model (client requests, server answers)  Text-based format (human readable)  Relies on unique resource URLs  Provides resource metadata (e.g. encoding)  Stateless (cookies and Web storages can overcome this) HTTP

 Client program  Running at end host  Requests a resource HTTP: Request-Response Protocol HTTP Request HTTP Response  Server program  Running at the server  Provides resources HTTP Client HTTP Server 32

33  HTTP request:  HTTP response: HTTP Conversation: Example HTTP/ OK Date: Mon, 5 Jul :09:03 GMT Server: Microsoft-HTTPAPI/2.0 Last-Modified: Mon, 12 Jul :33:23 GMT Content-Length: 54 <CRLF><html><title>Hello</title> Welcome to our site Welcome to our site The empty line denotes the end of the response header GET /courses/javascript HTTP/1.1 Host: User-Agent: Mozilla/5.0 <CRLF> The empty line denotes the end of the request header

34  HTTP defines request methods  Specify the action to be performed on the identified resource HTTP Request Methods MethodDescription GETRetrieve a resource (execute query) POSTCreates a resource PUTModifies a resource DELETERemove (delete) a resource HEADRetrieve the resource's headers OPTIONSRequests communication options

HTTP Request Message

36  Request message sent by a client consists of:  HTTP request line  Request method (GET / POST / PUT / DELETE / …)  Resource URI (URL)  Protocol version  HTTP request headers  Additional parameters  HTTP body – optional data, e.g. posted form fields HTTP Request Message HTTP/ HTTP/ <headers> (empty line) <body>

37  Example of HTTP GET request: HTTP GET Request – Example GET /courses/javascript HTTP/1.1 Host: Accept: */* Accept-Language: bg Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.0) Connection: Keep-Alive Cache-Control: no-cache <CRLF> HTTP request line HTTP request headers The request body is empty

38  Example of HTTP POST request: HTTP POST Request – Example POST /webmail/login.phtml HTTP/1.1 Host: Accept: */* Accept-Language: bg Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.0) Connection: Keep-Alive Cache-Control: no-cache Content-Length: 59 <CRLF>username=mente&password=top*secret!<CRLF> HTTP request line HTTP request headers The request body holds the submitted form data

39  Example of HTTP conditional GET request:  Fetches the resource only if it has been changed at the server  Server replies with "304 Not Modified" if the resource has not been changed  Or "200 OK" with the latest version otherwise Conditional HTTP GET – Example GET /apply HTTP/1.1 Host: User-Agent: Gecko/ Firefox/3.6 If-Modified-Since: Tue, 9 Mar :12:23 GMT <CRLF>

HTTP Response Message

41  The response message sent by the HTTP server consists of:  HTTP response status line  Protocol version  Status code  Status phrase  Response headers  Provide meta data about the returned resource  Response body  The content of the HTTP response (data) HTTP Response Message HTTP/ HTTP/

42  Example of HTTP response from the Web server: HTTP Response – Example HTTP/ OK Date: Fri, 17 Jul :09:18 GMT+2 Server: Apache/ (Linux) Accept-Ranges: bytes Content-Length: 84 Content-Type: text/html <CRLF><html> Test Test Test HTML page. Test HTML page. </html> HTTP response status line HTTP response headers The HTTP response body

43  Example of HTTP response with error result: HTTP Response – Example HTTP/ Not Found Date: Fri, 17 Nov :09:18 GMT+2 Server: Apache/ (Linux) Connection: close Content-Type: text/html <CRLF><HTML><HEAD> 404 Not Found 404 Not Found </HEAD><BODY> Not Found Not Found The requested URL /img/logo.gif was not found on this server. The requested URL /img/logo.gif was not found on this server. Apache/ Server at Port 80 Apache/ Server at Port 80 </BODY></HTML> HTTP response status line HTTP response headers The HTTP response body

44  HTTP response code classes  1xx: informational (e.g., "100 Continue")  2xx: successful (e.g., "200 OK", "201 Created")  3xx: redirection (e.g., "304 Not Modified", "301 Moved Permanently", "302 Found")  4xx: client error (e.g., "400 Bad Request", "404 Not Found", "401 Unauthorized", "409 Conflict")  5xx: server error (e.g., "500 Internal Server Error", "503 Service Unavailable") HTTP Response Codes

45  HTTP GET requesting a moved URL:  The following HTTP response (301 Moved Permanently) tells the browser to request another URL: Browser Redirection GET / HTTP/1.1 Host: User-Agent: Gecko/ Firefox/3.6 <CRLF> HTTP/ Moved Permanently Location: …

46  The Content-Type response header the server specifies how the output should be processed  Examples: Content-Type and Disposition Content-Type: text/html; charset=utf-8 Content-Type: application/pdf Content-Disposition: attachment; filename="Report-April-2010.pdf" UTF-8 encoded HTML page. Will be shown in the browser. This will download a PDF file named Financial-Report-April-2010.pdf

Redirecting the Browser

48  Done by using the HTTP " Location " header  This sends HTTP 302 "Found" in the HTTP response status codeHTTP 302 "Found"  Tells the browser to open a new URL Redirecting the Browser header('Location:

HTTP Compression Using Deflate and GZIP with HTTP

50 HTTP Compression: How It Works?

Caching HTTP Resources Cache Control HTTP Headers

52  HTTP cache control tags:  Cache-Control (no-cache, max-age, public, private, …)  ETag, Last-Modified  Expires, Last-Modified  If-Modified-Since HTTP Caching

? ? ? ? ? ? ? ? ? The HTTP Protocol

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 54

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg