HTTP: socket and requests
This commit is contained in:
parent
28ed52b969
commit
b548501d1a
4
HTTP/requests_client.py
Normal file
4
HTTP/requests_client.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
26
HTTP/socket_client.py
Normal file
26
HTTP/socket_client.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('vyatsu.ru', 80))
|
||||||
|
|
||||||
|
request = (
|
||||||
|
"GET / HTTP/1.1\r\n"
|
||||||
|
"Host: vyatsu.ru\r\n"
|
||||||
|
"User-Agent: python-requests/2.33.1\r\n"
|
||||||
|
"Accept-Encoding: gzip, deflate, zstd\r\n" # ← Закомментировали
|
||||||
|
"Accept: */*\r\n"
|
||||||
|
"Connection: close\r\n" # ← лучше keep-alive заменить на close
|
||||||
|
"\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
client.sendall(request.encode())
|
||||||
|
|
||||||
|
full_response = b""
|
||||||
|
while True:
|
||||||
|
chunk = client.recv(4096)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
full_response += chunk
|
||||||
|
|
||||||
|
print(full_response.decode())
|
||||||
|
client.close()
|
||||||
Loading…
Reference in New Issue
Block a user