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])