feat: add http socket and requests examples
This commit is contained in:
parent
1dcbe998b2
commit
6043efa685
@ -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])
|
||||||
@ -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])
|
||||||
Loading…
Reference in New Issue
Block a user