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 get response code with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to use HTTP2 with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to get a response with Python Aiohttp?
- How to get response text with Python Aiohttp?
- How to make parallel requests with Python Aiohttp?
More of Python Aiohttp
- How to get response text with Python Aiohttp?
- How to set headers in Python Aiohttp?
- How to set query parameters with Python Aiohttp?
- How to use HTTP2 with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to get JSON data using Python Aiohttp?
- How to get request parameters using Python Aiohttp?
- Setting CORS with Python Aiohttp?
- How to use keepalive with Python Aiohttp?
- How to handle x-www-form-urlencoded with Python Aiohttp?
See more codes...