How to send a POST request in Python?
In Python, you can use the requests library to send a POST request. Here is an example code:
import requests
# 构造POST请求的参数
data = {
'username': 'testuser',
'password': 'testpass'
}
# 发送POST请求
response = requests.post('http://example.com/login', data=data)
# 获取响应内容
print(response.text)
In the example above, we first created a dictionary called ‘data’ to be used as the parameter for the POST request. Then, we used the requests.post() method to send the POST request, with the first parameter being the URL of the request and the second parameter being the request data. Finally, we used response.text to retrieve the response content.