HTTP protocolAgreement: is a rule or regulationTCP/IP protocol:rules the communication format of TCP client and TCP server data
1. What are the Knowledge Points: HTTP protocol 2. What is the knowledge point: Specifies the data communication format between the browser and the server (TCP server) 3. Request Protocol Format < client (browser) send data to server >get/ index.html http/1.1 GET: /index.html: Address http/1.1: Protocol version 4. Response < server send data to client >
"The tcp-server sends data after receiving a client request"
#响应的格式 #1. The response header #2. Blank line #3. Response Body # 1. Response header "http1.1p version", OK: This is the status Header = "http/1.1 OK \ r \ n " #200这个是状态 Header + =" content-type:text/html;charset=utf-8 \ r \ n "#解析中文 header + =" content-length:5\r\n "#告诉浏览器显示多少 Characters # 2. Body of response body = "python10" content = header + "\ r \ n" + Body # Return data displayed on the page client.send (Content.encode ("UT F-8 ")) Note: If there is a return picture data, you need to return two times, first return the text encoding, and then return the binary picture data
Browser and server in HTTP
1. They use TCP sockets to implement the
HTTP process Response Header format
http/1.1 status \ r \ n
Format of the response
Response header http/1.1 \r\ncontent-type:text/html;charset = utf-8;\r\n #显示中文Content-length:10749 Display the length of the content blank line \r\ N Response Body (the contents of the returned data)
function of the request header
Tell the server we're requesting an address.
Data.splitlines () #GET/http/1.1: Response Header original Format Re.match (R ' [^/]+ (/[^]*) ', heads_01)#用正则的group得到地址file_name = Match.group (1)
The role of response
Control the display of the browser
State
the success of the 404 Not Found page does not exist 302 found jump 304 No permissions 500 server hangs
HTTP protocol (i)