# web应用程序
import socket
sock=socket.socket()
sock.bind(("127.0.0.1",8787))
sock.listen(5)
while 1:
print("server is working...")
conn,addr=sock.accept()
#接受请求数据
recv_data=conn.recv(1024)
print("recv_data\n",recv_data.decode())
with open("index.html","rb") as f:
data =f.read()
conn.send(b"HTTP/1.1 200 OK\r\n\r\n" + data)
conn.close()
sock.close()
<h1>hi huchangxi</h1>
<img src="https://imgcps.jd.com/ling4/100026667910/5Lqs6YCJ5aW96LSn/5L2g5YC85b6X5oul5pyJ/p-5f3a47329785549f6bc7a6f5/15fd9fad/cr/s/q.jpg">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>注册页面</h3>
<form action="http://127.0.0.1:8787" method="post">
<p>姓名 <input type="text" name="user" value="root"></p>
<p>密码 <input type="password" name="pwd" value="123456"></p>
<p><input type="submit"></p>
</form>
</body>
</html>