02 初级版web框架
服务器server端python程序(初级版):
import socket
server=socket.socket()
server.bind(("127.0.0.1",8888))
server.listen()
conn,client_addr=server.accept()
#接收到的请求信息
http_request=conn.recv(1024).decode()
print("请求信息:",http_request)
#conn.send(b'HTTP/1.1200ok\r\ncontent-type:text/html;charset=utf-8;\r\n')
conn.send("HTTP/1.1 200 ok \r\n\r\n".encode("utf-8"))
with open("初级版.html","rb")as f:
conn.send(f.read())
conn.close()
客户端浏览器访问:
在浏览器地址栏直接输入地址端口:127.0.0.1:8888
浏览器请求的文件有:
1. ip地址指向的主文件
2. jquery网络分发资源
3. 网络图片资源
4. 标签图标(head标签中的<link rel="icon" href="">)
初级版html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="refresh" content=""> <meta name="keywords" content=""> <style> #d1 { background-color: green; color: red; } </style> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> <link rel="icon" href=""> <title>初级版</title> </head> <body> <div id="d1"> <h1>初级版的页面:本html页面包含了css样式和js代码(其他网络资源)</h1> </div> <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1557925575771&di=9fc811dca1be2ae5e8084a2c106857bc&imgtype=0&src=http%3A%2F%2Fimg.kutoo8.com%2Fupload%2Fthumb%2F626516%2Fe97c1bbfa346d6c16138f1b1b7bf5d7e_960x540.jpg" alt="网络图片" title="网络图片"> </body> <script> alert("基础版的页面") </script> </html>