From 6043efa6859d924af3f0fda03faeca12fe9509b3 Mon Sep 17 00:00:00 2001 From: stud203788 Date: Thu, 7 May 2026 16:09:27 +0300 Subject: [PATCH] feat: add http socket and requests examples --- HTTP/http_requests.py | 12 ++++++++++++ HTTP/http_socket.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/HTTP/http_requests.py b/HTTP/http_requests.py index e69de29..056162d 100644 --- a/HTTP/http_requests.py +++ b/HTTP/http_requests.py @@ -0,0 +1,12 @@ +import requests + +url = "http://vyatsu.ru" + +response = requests.get(url) + +print("Статус-код:", response.status_code) +print("Заголовки ответа:") +print(response.headers) + +print("\nПервые 500 символов страницы:") +print(response.text[:500]) \ No newline at end of file diff --git a/HTTP/http_socket.py b/HTTP/http_socket.py index e69de29..0c91ea6 100644 --- a/HTTP/http_socket.py +++ b/HTTP/http_socket.py @@ -0,0 +1,29 @@ +import socket + +HOST = "vyatsu.ru" +PORT = 80 + +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +client.connect((HOST, PORT)) + +request = ( + "GET / HTTP/1.1\r\n" + "Host: vyatsu.ru\r\n" + "User-Agent: PythonSocketClient/1.0\r\n" + "Connection: close\r\n" + "\r\n" +) + +client.sendall(request.encode("utf-8")) + +response = b"" + +while True: + data = client.recv(4096) + if not data: + break + response += data + +client.close() + +print(response.decode("utf-8", errors="ignore")[:2000]) \ No newline at end of file