Chapter 2nd Introduction to--http AgreementIntroduction to the HTTP protocol
Abstract:http the features of the Protocol, the HTTP request/Response process, the HTTP request/Response message format, and finally shows how to track and debug an HTTP request using Chrome's developer tools.
HTTP protocol: Request-response protocol:
Client--Server:http request
Client <--server:http Response
An HTTP request and an HTTP response-one HTTP transaction
Any two HTTP transactions are independent and stateless
Protocol layering: Different protocols to accomplish different functions
Multiple layered Models: TCP/IP stack layering model, OSI layered model (layer seven), etc.
TCP/IP Layered model:
(Application layer) Application layer protocol: I.e HTTP protocol (HTTP request and response)
(Transport Layer) transport protocol: I.e TCP Protocol (Protocol to ensure orderly and reliable communication data)--port number (default)
Network Layer protocol: location (i.e IP address e.g. 93.184.216.34)--Bad remember, corresponding domain name: baidu.com
Domain-to-IP parsing: done by DNS (domain name System) server (name resolution Server)
IP address via domain name, plus port number to locate unique service
(host-to-network layer) Data Link layer & Physical Transport layer: data transfer
Process simulation for web browsing:
Domain Name: example.com
-DNS Server
IP Address: 93.184.216.34
Browser-side connect to server-side (IP address known): TCP connection
Connection established successfully
Browser side can initiate HTTP requests to server side
The server side can make the corresponding HTTP response
Browser-side rendering and presentation of HTML files
HTTP request and Response messages:
Enter the domain name in the browser address bar: Http://www.example.com:80/blahblah ...
http://-Protocol (the browser defaults to the HTTPS protocol, can be omitted)
www.example.com--Domain name
: 80--Port number (default: 80, can be omitted)
/blahblah ...--Resource path
HTTP request packet caught using the Grab kit: (message)
HTTP request Line: get/http/1.1 \ r \ n
Get---Request method: Get, POST, HEAD, PUT, OPTIONS, DELETE, TRACE, CONNECT
/---resource path
http/1.1---HTTP protocol version (currently used 1.1)
\ r \ n---End of text (line wrapping)
HTTP request header: From host to last row
Format: key:value \ r \ n
e.g.:
Host: domain name, hostname, virtual host
Connection: Use keep-alive a connection can send multiple requests, the request ends can not disconnect
User-agent: The application that originated the request (the server-side decision to return the version (PC or phone))
HTTP request body: This example is a simple get request, so there is no request body
HTTP response (message format):
Status line---http/1.1 OK \ r \ n
http/1.1---protocol version
---status code: Indicates the status of the HTTP response
OK---Reason
Common Status Codes:
OK: The request is successful (typically starting with 2 indicates a successful request)
304 Not Modified: (the request code is related to the cache: if the browser side has a cache, the server does not have to return when the resource is requested);
(typically starting with 3 is related to redirection and caching)
404 Not Found: (Resource not found on server side)
Internal Server Error: (server side error on request) (General 5 starts with error on server side)
\ r \ n---Terminator
Response Headers---from accept-ranges to content-length
Format is similar to the format of the request header
e.g.:
Server: What application is used on the server side to return the response
Content-type: Types of resource content (such as HTML, audio, video, etc.)
Content-length: Content Length (if there are multiple requests on a connection, you need to specify a resource length to find the boundary)
The part after the response body---The response header
Delimiter for response header and response body: blank line (\ r \ n)
The response body can be text or binary, in general the size is specified by the Content-length response header
The process of tracking responses via chrome:
Open the Developer-->tools Developer tool
Enter www.example.com
The process of getting an HTTP request
(The status code of www.example.com is 304; If disable cache is checked, the status code will be 200)
Click www.example.com to view details
Java Development Engineer (Web orientation)-Introduction to 01.Java Web Development-2nd Chapter. Introduction to the HTTP protocol