python socket web


import socket

'''
b'GET /index?name=jww HTTP/1.1\r\n
Host: 127.0.0.1:8080\r\n
Connection: keep-alive\r\n
sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"\r\n
sec-ch-ua-mobile: ?0\r\n
sec-ch-ua-platform: "Windows"\r\n
Upgrade-Insecure-Requests: 1\r\n
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n
Sec-Fetch-Site: none\r\n
Sec-Fetch-Mode: navigate\r\n
Sec-Fetch-User: ?1\r\n
Sec-Fetch-Dest: document\r\n
Accept-Encoding: gzip, deflate, br\r\n
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8\r\n
\r\n'

'''

server = socket.socket()
server.bind(('127.0.0.1',8081))
server.listen(5)
i=0
while True:
conn, addr = server.accept()
data = conn.recv(1024)
print(data)
s_data = f'HTTP/1.1 200 ok\r\n\r\nhello {i}'
i+=1
conn.send(s_data.encode('utf-8'))
conn.close()
posted @ 2022-08-11 16:42  MoonXu  阅读(58)  评论(0编辑  收藏  举报