How to use Python to submit data with POST?

In Python, you can use the requests library to make a POST request and submit data. Here is a basic example code:

import requests

# 提交的数据
data = {
    'username': 'admin',
    'password': '123456'
}

# 发送POST请求并提交数据
response = requests.post('http://example.com/login', data=data)

# 输出响应结果
print(response.text)

In this example, the requests library is imported first. Then a dictionary called data is created to store the data to be submitted. The requests.post() method is used to send a POST request, passing the URL and data as parameters. Finally, the server’s response can be obtained through the response.text attribute and printed out.

Please note that this is just a basic example and you may need to configure more details according to your specific situation, such as setting request headers and handling exceptions.

bannerAds