python-aiohttpHow to make a POST request with Python Aiohttp?
Making a POST request with Python Aiohttp is easy. You can use the aiohttp.ClientSession.post()
method to make a POST request.
Example code
import aiohttp
async with aiohttp.ClientSession() as session:
async with session.post('http://example.com/post', data={'key':'value'}) as resp:
print(resp.status)
print(await resp.text())
Output example
200
<html>...</html>
Code explanation
import aiohttp
: imports the aiohttp libraryasync with aiohttp.ClientSession() as session
: creates a ClientSession objectasync with session.post('http://example.com/post', data={'key':'value'}) as resp
: makes a POST request to the specified URL with the given dataprint(resp.status)
: prints the response status codeprint(await resp.text())
: prints the response body
Helpful links
Related
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to close a Python Aiohttp session?
- How to rate limit with Python Aiohttp?
More of Python Aiohttp
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to get response text with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to retry a request with Python Aiohttp?
- How to set query parameters with Python Aiohttp?
- How to make parallel requests with Python Aiohttp?
- How to get response code with Python Aiohttp?
See more codes...