Код: Выделить всё
import http.client
PROXY = {'host': "10.20.30.40", 'port': 3128}
TARGET = {'host': "example.com", 'port': 443, 'url': "/api/v1/data"}
HEADERS = {'Host': TARGET.get('host'), 'User-agent': "Python http.client"}
TIMEOUT = 10
if port := TARGET.get('port') == 443:
conn = http.client.HTTPSConnection(PROXY.get('host'), port=PROXY.get('port'), timeout=TIMEOUT)
conn.set_tunnel(host=TARGET.get('host'), port=TARGET.get('port', 443))
else:
conn = http.client.HTTPConnection(PROXY.get('host'), port=PROXY.get('port'), timeout=TIMEOUT)
conn.request(method="GET", url=TARGET.get('url', "/"), headers=HEADERS)
response = conn.getresponse()
conn.close()
print(response.status, response.reason)
Код: Выделить всё
TARGET = {'host': "example.com", 'port': 80, 'url': "/api/v1/data"}
Код: Выделить всё
192.168.1.100 NONE_NONE/400 3885 GET /api/v1/data - HIER_NONE/- text/html
Код: Выделить всё
192.168.1.100 TCP_MISS/200 932 GET http://example.com/api/v1/data - HIER_DIRECT/203.0.113.132 application/json
Подробнее здесь: https://stackoverflow.com/questions/792 ... https-site