Add basic HTTP/2 example
This commit is contained in:
parent
c6ac417946
commit
0c7119dbeb
26
src/examples/httpx-example.py
Normal file
26
src/examples/httpx-example.py
Normal file
@ -0,0 +1,26 @@
|
||||
import asyncio
|
||||
import httpx
|
||||
|
||||
|
||||
async def make_http2_request(url):
|
||||
try:
|
||||
async with httpx.AsyncClient(http2=True, verify=False) as client:
|
||||
response = await client.get(url)
|
||||
return response
|
||||
except httpx.RequestError as e:
|
||||
print(f'[!] error occurred while making the request: {e}')
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
url = 'https://localhost/'
|
||||
|
||||
response = asyncio.run(make_http2_request(url))
|
||||
|
||||
print('Response object type:', type(response))
|
||||
print('Response HTTP version:', response.http_version)
|
||||
print('Response headers:', response.headers)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,2 +1,3 @@
|
||||
httpx
|
||||
h2
|
||||
asyncio
|
||||
h2
|
||||
httpx[http2]
|
||||
|
Loading…
Reference in New Issue
Block a user