Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hypertext Transfer Protocol

Similar presentations


Presentation on theme: "Hypertext Transfer Protocol"— Presentation transcript:

1 Hypertext Transfer Protocol

2 Overview An application-level protocol. Since 1990. Connectionless
Media independent Stateless Client-Server HTTP Version <major>.<minor> HTTP/1.0 HTTP/1.1

3 HTTP - Parameters HTTP Version
HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT Uniform Resource Identifiers URI = " "//" host [ ":" port ] [ abs_path [ "?" query ]] Character Sets US-ASCII ISO ISO Content Encodings Accept-encoding: gzip Accept-encoding: compress Accept-encoding: deflate

4 HTTP - Messages Connection Over TCPI/IP HTTP-message
Request Response Generic message format A Start-line Zero or more header fields followed by CRLF An empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields Optionally a message-body

5 HTTP - Messages Message Start-Line Header Fields Message-header
field-name ":" [ field-value ] User-Agent: curl/ libcurl/ OpenSSL/ Host: Accept-Language: en, mi Date: Mon, 27 Jul :28:53 GMT Server: Apache Last-Modified: Wed, 22 Jul :15:56 GMT Accept-Ranges: bytes Content-Length: 51 Content-Type: text/plain Message Start-Line Request-Line GET /hello.htm HTTP/1.1 Status-Line HTTP/ OK Header Fields General-header Request-header Response-header Entity-header

6 HTTP- Message Body Content-Type and Content-Length headers lines specify the nature of the body associated. Carries the actual HTTP request data (including form data and uploaded, etc.) and HTTP response data from the server ( including files, images, etc.). A simple content of a message body: <html> <body> <h1>Hello, World!</h1> </body> </html>

7 HTTP - Requests General Format Request-Line Request Method
A Request-line Zero or more header fields followed by CRLF An empty line Optionally a message-body Request-Line Begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF. The elements are separated by space SP characters. Request-Line = Method SP Request-URI SP HTTP-Version CRLF Request Method Indicates the method to be performed on the resource identified by the Request-URI. Is case-sensitive and should always be mentioned in uppercase.

8 HTTP – Request Methods GET: Is used to retrieve information from the given server using a given URI. Requests using GET only retrieve data and have no other effect on the data. HEAD: Same as GET, but it transfers the status line and the header section only. POST: Is used to send data to the server using HTML forms. (customer information, file upload, etc). PUT: Replaces the target resource with the uploaded content. DELETE : Removes the target resource given by URI. CONNECT: Establishes a tunnel to the server identified by a given URI OPTIONS : Describe the communication options for the target resource. TRACE : Performs a message loop back test along with the path to the target resource.

9 HTTP – Request Request-URI Request Header Fields
Identifies the resource which to apply the request. GET /pub/WWW/TheProject.html HTTP/1.1 Host: Request Header Fields Allow the client to pass additional information about the request and itself Accept-Charset Accept-Encoding Accept-Language Authorization Host User-Agent

10 HTTP – Request Examples
GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 Host: Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive POST /cgi-bin/process.cgi HTTP/1.1 User-Agent: Mozilla/4.0 Host: Content-Type: application/x-www-form-urlencoded Content-Length: length Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive licenseID=string&content=string&/paramsXML=string

11 HTTP – Request Examples
POST /cgi-bin/process.cgi HTTP/1.1 User-Agent: Mozilla/4.0 Host: Content-Type: text/xml; charset=utf-8 Content-Length: length Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive <?xml version="1.0" encoding="utf-8"?> <string xmlns="

12 HTTP - Responses General Format Status Code A Status-line
Zero or more header fields followed by CRLF An empty line Optionally a message-body Status Code 1xx: Informational It means the request was received and the process is continuing. 2xx: Success It means the action was successfully received, understood, and accepted. 3xx: Redirection It means further action must be taken in order to complete the request. 4xx: Client Error It means the request contains incorrect syntax or cannot be fulfilled. 5xx: Server Error It means the server failed to fulfill an apparently valid request.

13 HTTP – Responses Example
HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Last-Modified: Wed, 22 Jul :15:56 GMT Content-Length: 88 Content-Type: text/html Connection: Closed <html> <body> <h1>Hello, World!</h1> </body> </html> HTTP/ Not Found Date: Sun, 18 Oct :36:20 GMT Server: Apache/ (Win32) Content-Length: 230 Connection: Closed Content-Type: text/html; charset=iso <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>404 Not Found</title> </head> <body> <h1>Not Found</h1> <p>The requested URL /t.html was not found on this server.</p> </body> </html>

14 HTTP – Responses Example
HTTP/ Bad Request Date: Sun, 18 Oct :36:20 GMT Server: Apache/ (Win32) Content-Length: 230 Content-Type: text/html; charset=iso Connection: Closed <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>400 Bad Request</title> </head> <body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.</p> <p>The request line contained invalid characters following the protocol string.</p> </body></html>

15 HTTP – Request Responses GET Example
GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 Host: Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Last-Modified: Wed, 22 Jul :15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed <html> <body> <h1>Hello, World!</h1> </body> </html>

16 HTTP – Request Responses HEAD Example
HEAD /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 Host: Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Last-Modified: Wed, 22 Jul :15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed

17 HTTP – Request Responses POST Example
POST /cgi-bin/process.cgi HTTP/1.1 User-Agent: Mozilla/4.0 Host: Content-Type: text/xml; charset=utf-8 Content-Length: 88 Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive <?xml version="1.0" encoding="utf-8"?> <string xmlns=" HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Last-Modified: Wed, 22 Jul :15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed <html> <body> <h1>Request Processed Successfully</h1> </body> </html>

18 HTTP – Request Responses PUT Example
PUT /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 Host: Accept-Language: en-us Connection: Keep-Alive Content-type: text/html Content-Length: 182 <html> <body> <h1>Hello, World!</h1> </body> </html> HTTP/ Created Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Content-type: text/html Content-length: 30 Connection: Closed <html> <body> <h1>The file was created.</h1> </body> </html>

19 HTTP – Request Responses DELETE Example
DELETE /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 Host: Accept-Language: en-us Connection: Keep-Alive HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Content-type: text/html Content-length: 30 Connection: Closed <html> <body> <h1>URL deleted.</h1> </body> </html>

20 HTTP – Request Responses DELETE Example
CONNECT HTTP/1.1 User-Agent: Mozilla/4.0 HTTP/ Connection established Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32)

21 HTTP – Request Responses OPTIONS Example
OPTIONS * HTTP/1.1 User-Agent: Mozilla/4.0 HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/ (Win32) Allow: GET,HEAD,POST,OPTIONS,TRACE Content-Type: httpd/unix-directory

22 HTTP – Request Responses TRACE Example
TRACE / HTTP/1.1 Host: User-Agent: Mozilla/4.0 HTTP/ OK Date: Mon, 27 Jul :28:53 GMT Server: Apache/2.2.14 Connection: close Content-Type: message/http Content-Length: 39 TRACE / HTTP/1.1 Host: User-Agent: Mozilla/4.0

23 HTTP - Status Codes 1xx: Information 2xx: Successful
100 Continue : only a part of the request has been received by the server, but as long as it has not been rejected, the client should continue with the request. 101 Switching Protocols : The server switches protocol. 2xx: Successful 200 OK: The request is OK. 201 Created: The request is complete, and a new resource is created . 202 Accepted: The request is accepted for processing, but the processing is not complete. 203 Non-authoritative Information 204 No Content 205 Reset Content 206 Partial Content

24 HTTP - Status Codes 3xx: Redirection 4xx: Client Error
300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 305 Use Proxy 4xx: Client Error 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed ….

25 HTTP - Status Codes 5xx: Server Error 500 Internal Server Error
501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported

26 HTTP - Caching The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases. Server specifies expiration times and validators usıng the Cache-Control headers. The Cache-Control header allows a client or server to transmit a variety of directives in either requests or responses. The caching directives are specified in a comma-separated list. Cache-control: no-cache

27 HTTP - Caching Possible cache request directives by the client
no-cache no-store max-age = seconds max-stale [ = seconds ] min-fresh = seconds no-transform only-if-cached Possible cache response directives by the server public private no-cache no-store no-transform must-revalidate max-age = seconds


Download ppt "Hypertext Transfer Protocol"

Similar presentations


Ads by Google