From 1b8429e76e2d4dcebb9cff66ede844984cb0458d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A0=D0=B5=D0=BF=D0=B8?= =?UTF-8?q?=D0=BD?= Date: Mon, 30 Nov 2026 15:14:56 +0300 Subject: [PATCH] feat: add HTTP requests and socket clients --- http_requests_test.py | 7 +++++++ http_socket_client.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 http_requests_test.py create mode 100644 http_socket_client.py diff --git a/http_requests_test.py b/http_requests_test.py new file mode 100644 index 0000000..db08768 --- /dev/null +++ b/http_requests_test.py @@ -0,0 +1,7 @@ +import requests + +response = requests.get("http://vyatsu.ru") +print("Итоговый URL после редиректа:", response.url) +print("Статус ответа:", response.status_code) +print("Фрагмент HTML-страницы:\n") +print(response.text[:500]) diff --git a/http_socket_client.py b/http_socket_client.py new file mode 100644 index 0000000..a562363 --- /dev/null +++ b/http_socket_client.py @@ -0,0 +1,32 @@ +import socket +import ssl + +host = 'vyatsu.ru' +port = 443 + +# Оборачиваем TCP-сокет в SSL/TLS, так как vyatsu.ru перенаправляет HTTP (80) на HTTPS (443) +context = ssl.create_default_context() +raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +with context.wrap_socket(raw_sock, server_hostname=host) as client: + client.connect((host, port)) + + # Заголовки, аналогичные библиотеке requests + request = ( + f"GET / HTTP/1.1\r\n" + f"Host: {host}\r\n" + f"User-Agent: python-requests/2.32.0\r\n" + f"Accept-Encoding: identity\r\n" + f"Accept: */*\r\n" + f"Connection: close\r\n\r\n" + ) + client.sendall(request.encode('utf-8')) + + response = b"" + while True: + chunk = client.recv(4096) + if not chunk: + break + response += chunk + +print(response.decode('utf-8', errors='ignore')[:700])