feat: add http socket and requests examples

This commit is contained in:
Артём Садаков 2026-05-07 16:09:27 +03:00
parent 1dcbe998b2
commit 6043efa685
2 changed files with 41 additions and 0 deletions

View File

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

View File

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