Http Request Header | Teach You to Get Started With Python One -hundred and Eleven

Http Request Header | Teach You to Get Started With Python One -hundred and Eleven

Http Request Header.This section describes what HTTP request headers contain.

Http Request Header.HTTP request header

In the previous section, we mainly talked about the response header. We did not pay attention to what is in the request header. Run the following code:
import socket

server_socket = socket.socket ( socket.AF_INET , socket.SOCK_STREAM ) _ _ _ _
server_ socket.bind (( '' , 8090 ))
server_socket.listen ( 128 ) _
while True:
client_socket , client_addr = server_socket.accept ( )
data = client_socket.recv ( 1024 ).decode( ' utf8' )
print( 'Received data from {}{}' . format ( client_addr [ 0 ], data))

client_socket.send('HTTP/1.1 200 OK '.encode('utf8'))
client_socket.send('content-type:text/html '.encode('utf8'))
client_socket.send(' '.encode('utf8'))

client_ socket. send ( '

hello world

' .encode( 'utf8' ))
Browser access results:
The first sentence of the request header GET / HTTP/1.1 means:
•GET request method, GET/POST/PUT/DELETE...
•/request path
•HTTP/1.1 HTTP version number
At this point we change the access path:
You can see that the first sentence of the request header becomes GET / index.html?name = jack&age =18 HTTP/1.1, indicating that the middle part can also represent the parameters of the request.
The second sentence of the request header Host: indicates the requested server address.
Other information is temporarily ignored. It is browser-related information. Simply explain UA: User Agent. The purpose of the original design is to identify the type of browser from the request header.

Http Request Header.Binding of IP addresses

ip address can only be accessed through the ip address. If you change the bound address to, you can use this address to access (or access localhost) in the browser:

The we used in the previous sections can also represent the local machine. It represents all available addresses. If is used, it can only be accessed through the local machine, and others cannot access it. It can be seen that if it is on the cloud server For deployment, it is more convenient to use

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00