1.web Reference Program
The web, also known as the World Wide Web, is a global, dynamically interactive, cross-platform distributed graphical information system based on hypertext and HTTP (wide). is a Web service built on the Internet that provides a graphical, easy-to-access, and intuitive interface for browsing and browsing information on the Internet
An application that can be accessed through the Web, usually b/s mode
1.1http protocol
Hyper text Transfer Protocol, Hypertext Transfer Protocol for transfer of text between a World Wide Web server and a local browser
1.2http protocol Features
Application layer protocol based on TCP/IP protocol
Based on request-response mode (one-time handshake)
The HTTP protocol itself does not save the communication state between the request and the response
When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. This way, the transmission time can be saved
1.3http request agreement and corresponding protocol
About the Request protocol format
Note: Get is different from POST request
Get submitted data is placed after the URL, in the? Splitting URLs and transferring data, connecting parameters with &
The data size of the Get commit is limited (because the browser has a limit on the URL length), and the post has
About the Request protocol format
Response Status Code
The result of the request returned when the client-side service sends a request. The status code can be used to know if the server is processing the request correctly, and the response is divided into the following five types
1.2 Browser emulation socket client interacts with Python server
The browser is actually the client that encapsulates the socket, and in Python it responds to the browser client by simulating the server.
ImportSocketser=socket.socket () port= ('127.0.0.1', 8800) Ser.bind (port) ser.listen () whileTrue:Print('Server waitting') conn,addr=ser.accept () msg= CONN.RECV (1024) Print("Data", msg)#reading HTML filesWith open ("day2.html","RB") as F:data=F.read ()#fixed syntax format, based on the 1.1 version of the HTTP protocolConn.send (b'http:\\1.1 ok\r\n\r\n%s'%data) Conn.close ()
Day2.html
<! DOCTYPE html>"ZH-CN">"UTF-8"> <title> Login Interface </title>p{Color:gray; Background-Color:yellow; } </style> <form> <textarea name="Stay White"Rows="4"cols=" the"> </textarea> </form> <fieldset> <div align="Center"> "username"Placeholder="Email/Mobile account/Xiaomi ID"><br><br> <input type="Password"Placeholder="Password"><br><br> <a href=""> Sign in </a> </fieldset> </div></body>View CodeRun the server first, open the browser at this time, the above input 127.0.0.1:8800 can respond to the message from the server side, print the service side of the information
51.web applications