Add socket and request clients
This commit is contained in:
parent
820aa0e123
commit
a681343c5c
4
http/request_client.py
Normal file
4
http/request_client.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
24
http/socket_client.py
Normal file
24
http/socket_client.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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: keep-alive\r\n"
|
||||||
|
"\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
client.sendall(request.encode())
|
||||||
|
|
||||||
|
response = b""
|
||||||
|
while chunk := client.recv(4096):
|
||||||
|
response += chunk
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
body = response.split(b"\r\n\r\n", 1)[1]
|
||||||
|
print(body.decode()[:500])
|
||||||
Loading…
Reference in New Issue
Block a user