HTTP : Protocol for transfer of various data formats between server and clients
Plaintext : TXT,CSS
Hypertext: HTML
Images: GIF, JPEG
Video: AVI, MPEG
Sound: MP3, MIDI
https://www.google.com/test/index.html?username=test
URL Protocol Scheme, Server Location (Host), URI, Query
HTTP REQUEST AND RESPONSE MESSAGE
Request message format
|
Response message format
|
Request line
|
Status line
|
Headers
|
Headers
|
A blank line
|
A blank line
|
Body (present only in some messages)
|
Body (present only in some messages)
|
HTTP Request format
GET /doc/test.html HTTP/1.1
|
Request Line
|
Request Headers
| |
Accept-Language: en-us
| |
Accept-Encoding: gzip, deflate
| |
User-Agent : Mozilla/4.0
| |
Content-Length: 35
| |
------------------------------------------------------------
|
A blank line separates header and body
|
bookId=12345&author=Tan+Ah+Teck
|
Request message body
|
Request Line syntax – request-method-name request-URI-path of resource HTTP-version-1.0/1.1/2.0
request-method-name
Get – Returns an object, shouldn’t have a body
Head – Returns info about object
Post – Sends info to be stored on server or as input to script (Should have a body)
Options – query the server which request methods are supported
Trace – ask the server to return a diagnostic trace
Put – sends new copy of existing object to server, usually not allowed
Delete – deletes object, usually not allowed
Request Headers
Format is as “name: value” pairs
Request-header-name1: value1 <CRLF, Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n) >
Request-header-name2: value2 <CRLF, Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n) >
Accept: mime-type-1, mime-type-2,… - Multipurpose Internet Mail Extensions, header is a way for a client to specify the media type of the response content it is expecting.
Accept-Language: language-1, language-2, …. - client tells server which language it can handle.
Accept-Encoding: encoding-method1,.. – client tells server which encoding type it supports.
Connection: Close | Keep-Alive – keep TCP connection open for another request.
User-Agent: browser-type – Identify the type of browser used to make request.
Referer: referrer-URL- if you click a link from webpage1 to visit web page2, web page1 is referrer for request to web page 2.
POST request method is used to “post” additional data up to the server (e.g., submitting HTML form data or uploading a file)
Content-Type: -informs the server the data is URL-encoded (with a special MIME type application/x-www-form-urlencoded).
Content-Length: - tells the server how many bytes to read from the message body.
Cookie: Some_Name=Some_value – sent by client to server for maintaining statefull session
Multipurpose Internet Mail Extensions
Extends the format of email to support. Content-Type header indicates the media type of the message content, consisting of a type and subtype.
· Text in character sets other than ASCII Content-Type: text/plain
· Non-text attachments: audio, video, images, application programs etc. image/jpeg, audio/mp3, video/mp4, and application/msword
· Message bodies with multiple parts multipart/form-data
· Header information in non-ASCII character sets
Example :-
POST /bin/login HTTP/1.1
HOST: 127.0.0.1:8000
Accept: image/gif, image/jpeg, */*
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Content-Length: 37
Connection: Keep-Alive
Cache-Control: no-cache
# Blank line – request body starts from here #
User=Peter+Lee&pw=123456&action=login
HTTP Response format
HTTP/1.1 200 OK
|
Status Line
|
Date: Sun, 08 Feb 2019 01:11:12 GMT
|
Response Headers
|
Server: Apache/1.3.29 (Win32)
| |
Last-Modified: Sat, 07 Feb 2019
| |
ETag: “0-23-4024c3a5”
| |
Accept-Ranges: bytes
| |
Content-Length: 35
| |
Connection: close
| |
Set-Cookie: Some_Name=Some_Value; expires=Mon; 21-Aug-2017 10:56:58 GMT; path=/; domain=example.com; HttpOnly
| |
Content-Type: text/html
| |
---------------------------------------------
|
A blank line separates header and body
|
<h1>My Home page</h1>
|
Response Message Body
|
Staus Line Sytax : HTTP-version status-code description-text
Status-codes
1xx (Informational): Request received, server is continuing the process.
· 101 Continue: The server received the request and in the process of giving the response.
2xx (Success): The request was successfully received, understood, accepted and serviced.
· 200 OK: The request is fulfilled.
· 204 No Content: There is no content to send in the response payload body (Content served from cache)
3xx (Redirection): Further action must be taken in order to understand.
· 301 Move Permanently: The resource requested for has been permanently moved to a new location. Application should update all references to this new location.
· 302 Move Temporarily: Same as 301, but the new location is temporarily in nature. The client should issue a new request, but applications need not update the references.
· 304 Not Modified: In response to the If-Modified-Since conditional GET request, the server notifies that the resource requested has not been modified.
4xx (Client Error): The request contains bad syntax or cannot be understood.
· 400 Bad Request: Server could not interpret or understand the request, probably syntax error in the request message.
· 401 Authentication Required: The requested resource is protected, and require client’s credential (Username/password). The client should re-submit the request with his credential (username/password).
· 403 Forbidden: Server refuses to supply the resource, regardless of identity of client.
· 404 Not Found: The requested resource cannot be found in the server.
5xx (Server Error): The server failed to fulfill an apparently valid request.
· 500 Internal Server Error: Server is confused, often caused by an error in the server-side program responding to the request.
· 502 Bad Gateway: Proxy or Gateway indicates that it receives a bad response from the upstream server.
Response Header
Server
|
Type of server
|
Date
|
Date and time
|
Content-Length
|
Number of bytes
|
Content-Type
|
Mime type
|
Content-Language
|
English, for example
|
Content-Encoding
|
Data compression
|
Last-Modified
|
Date when last modified
|
Set-Cookie
|
Sent to client by server
|
Expires
|
Date when file becomes invalid
|
No comments:
Post a Comment