From b548501d1a3b6f3aeb4bb7322affbd1a518de053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Mon, 4 May 2026 20:34:05 +0300 Subject: [PATCH] HTTP: socket and requests --- HTTP/requests_client.py | 4 ++++ HTTP/socket_client.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 HTTP/requests_client.py create mode 100644 HTTP/socket_client.py diff --git a/HTTP/requests_client.py b/HTTP/requests_client.py new file mode 100644 index 0000000..83588ae --- /dev/null +++ b/HTTP/requests_client.py @@ -0,0 +1,4 @@ +import requests + +response = requests.get("http://vyatsu.ru") +print(response.text[:500]) \ No newline at end of file diff --git a/HTTP/socket_client.py b/HTTP/socket_client.py new file mode 100644 index 0000000..db4e0ae --- /dev/null +++ b/HTTP/socket_client.py @@ -0,0 +1,26 @@ +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +client.connect(('vyatsu.ru', 80)) + +request = ( + "GET / HTTP/1.1\r\n" + "Host: vyatsu.ru\r\n" + "User-Agent: python-requests/2.33.1\r\n" + "Accept-Encoding: gzip, deflate, zstd\r\n" # ← Закомментировали + "Accept: */*\r\n" + "Connection: close\r\n" # ← лучше keep-alive заменить на close + "\r\n" +) + +client.sendall(request.encode()) + +full_response = b"" +while True: + chunk = client.recv(4096) + if not chunk: + break + full_response += chunk + +print(full_response.decode()) +client.close()