python-aiohttpHow to handle x-www-form-urlencoded with Python Aiohttp?
X-www-form-urlencoded is a format used to send data to a server. It can be handled with Python Aiohttp by using the aiohttp.FormData
class.
import aiohttp
async with aiohttp.ClientSession() as session:
form_data = aiohttp.FormData()
form_data.add_field('name', 'value')
async with session.post('http://example.com', data=form_data) as resp:
print(resp.status)
Output example
200
Code explanation
import aiohttp
: imports the aiohttp libraryaiohttp.FormData
: creates a FormData objectform_data.add_field('name', 'value')
: adds a field to the FormData objectsession.post('http://example.com', data=form_data)
: sends the FormData object to the serverresp.status
: prints the response status code
Helpful links
Related
- How to get response code with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to download large files with Python Aiohttp?
- How to disable SSL verification in Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to close a Python Aiohttp session?
More of Python Aiohttp
- How to reuse a session with Python Aiohttp?
- How to rate limit with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to retry a request with Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to set query parameters with Python Aiohttp?
- How to use HTTP2 with Python Aiohttp?
- How to close a Python Aiohttp session?
See more codes...