赞
踩
GET 请求原始报文说明:
GET / HTTP/1.1\r\n
Host: www.itcast.cn\r\n
Connection: keep-alive\r\n
Upgrade-Insecure-Requests: 1\r\n
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Language: zh-CN,zh;q=0.9\r\n
Cookie: pgv_pvi=1246921728; \r\n
\r\n (请求头信息后面还有一个单独的’\r\n’不能省略)
说明:
每项数据之间使用:\r\n
POST 请求报文说明:
---- 请求行 ----
POST /xmweb?host=mail.itcast.cn&_t=1542884567319 HTTP/1.1 # POST请求方式 请求资源路径 HTTP协议版本
---- 请求头 ----
Host: mail.itcast.cn # 服务器的主机地址和端口号,默认是80
Connection: keep-alive # 和服务端保持长连接
Content-Type: application/x-www-form-urlencoded # 告诉服务端请求的数据类型
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 # 客户端的名称
---- 空行 ----
---- 请求体 ----
username=hello&pass=hello # 请求参数
POST 请求原始报文说明:
POST /xmweb?host=mail.itcast.cn&_t=1542884567319 HTTP/1.1\r\n
Host: mail.itcast.cn\r\n
Connection: keep-alive\r\n
Content-Type: application/x-www-form-urlencoded\r\n
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n
\r\n(请求头信息后面还有一个单独的’\r\n’不能省略)
username=hello&pass=hello
说明:
每项数据之间使用:\r\n
响应报文说明:
— 响应行/状态行 —
HTTP/1.1 200 OK # HTTP协议版本 状态码 状态描述
— 响应头 —
Server: Tengine # 服务器名称
Content-Type: text/html; charset=UTF-8 # 内容类型
Transfer-Encoding: chunked # 发送给客户端内容不确定内容长度,发送结束的标记是0\r\n, Content-Length表示服务端确定发送给客户端的内容大小,但是二者只能用其一。
Connection: keep-alive # 和客户端保持长连接
Date: Fri, 23 Nov 2018 02:01:05 GMT # 服务端的响应时间
— 空行 —
— 响应体 —
… # 响应给客户端的数据原始响应报文说明:
HTTP/1.1 200 OK\r\n
Server: Tengine\r\n
Content-Type: text/html; charset=UTF-8\r\n
Transfer-Encoding: chunked\r\n
Connection: keep-alive\r\n
Date: Fri, 23 Nov 2018 02:01:05 GMT\r\n
\r\n(响应头信息后面还有一个单独的’\r\n’不能省略)
…说明:
每项数据之间使用:\r\n
import socket
if name == ‘main’:
tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
tcp_server_socket.bind((“”, 9000))
tcp_server_socket.listen(128)
while True:
new_socket, ip_port = tcp_server_socket.accept()
recv_client_data = new_socket.recv(4096)
recv_client_content = recv_client_data.decode(“utf-8”)
print(recv_client_content)
with open(“static/index.html”, “rb”) as file:
file_data = file.read()
response_line = “HTTP/1.1 200 OK\r\n”
response_header = “Server: PWS1.0\r\n”
response_body = file_data
response_data = (response_line + response_header + “\r\n”).encode(“utf-8”) + response_body
new_socket.send(response_data)
new_socket.close()
import socket
def main():
tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
tcp_server_socket.bind((“”, 9000))
tcp_server_socket.listen(128)
while True:
new_socket, ip_port = tcp_server_socket.accept()
recv_client_data = new_socket.recv(4096)
if len(recv_client_data) == 0:
print(“关闭浏览器了”)
new_socket.close()
return
recv_client_content = recv_client_data.decode(“utf-8”)
print(recv_client_content)
request_list = recv_client_content.split(" ", maxsplit=2)
request_path = request_list[1]
print(request_path)
if request_path == “/”:
request_path = “/index.html”
try:
with open(“static” + request_path, “rb”) as file:
file_data = file.read()
except Exception as e:
response_line = “HTTP/1.1 404 Not Found\r\n”
response_header = “Server: PWS1.0\r\n”
with open(“static/error.html”, “rb”) as file:
file_data = file.read()
response_body = file_data
response_data = (response_line + response_header + “\r\n”).encode(“utf-8”) + response_body
new_socket.send(response_data)
else:
response_line = “HTTP/1.1 200 OK\r\n”
response_header = “Server: PWS1.0\r\n”
response_body = file_data
response_data = (response_line + response_header + “\r\n”).encode(“utf-8”) + response_body
new_socket.send(response_data)
finally:
new_socket.close()
if name == ‘main’:
main()
import socket
import threading
def handle_client_request(new_socket):
recv_client_data = new_socket.recv(4096)
if len(recv_client_data) == 0:
print(“关闭浏览器了”)
new_socket.close()
return
recv_client_content = recv_client_data.decode(“utf-8”)
print(recv_client_content)
request_list = recv_client_content.split(" ", maxsplit=2)
request_path = request_list[1]
print(request_path)
if request_path == “/”:
request_path = “/index.html”
try:
with open(“static” + request_path, “rb”) as file:
file_data = file.read()
except Exception as e:
response_line = “HTTP/1.1 404 Not Found\r\n”
response_header = “Server: PWS1.0\r\n”
with open(“static/error.html”, “rb”) as file:
file_data = file.read()
response_body = file_data
response_data = (response_line + response_header + “\r\n”).encode(“utf-8”) + response_body
new_socket.send(response_data)
else:
response_line = “HTTP/1.1 200 OK\r\n”
response_header = “Server: PWS1.0\r\n”
response_body = file_data
response_data = (response_line + response_header + “\r\n”).encode(“utf-8”) + response_body
new_socket.send(response_data)
finally:
new_socket.close()
def main():
tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
tcp_server_socket.bind((“”, 9000))
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
喜欢的话别忘了关注、点赞哦~
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。*
深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-cLgmydb6-1711002900529)]
[外链图片转存中…(img-Rvc3hr4G-1711002900530)]
[外链图片转存中…(img-3HlnCyK2-1711002900530)]
[外链图片转存中…(img-s7VuSrjS-1711002900530)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
[外链图片转存中…(img-EuA9ZSBV-1711002900531)]
喜欢的话别忘了关注、点赞哦~
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。