How can you retrieve the POST results in Python?
In Python, you can use the requests library to send a POST request and retrieve the results.
Firstly, make sure the requests library has been installed. It can be installed using the following command:
pip install requests
Next, you can use the following code to send a POST request and retrieve the results.
import requests
url = 'http://example.com' # 替换为需要发送POST请求的URL
data = {'key1': 'value1', 'key2': 'value2'} # 替换为需要发送的POST数据
response = requests.post(url, data=data)
print(response.text) # 打印POST请求的结果
In the code above, the requests library is imported first. Next, the URL and data to be sent in the POST request are defined. The requests.post() function is used to send the POST request, and the result is assigned to the response variable. Lastly, the result of the POST request can be obtained by using response.text, and it can be printed using the print() function.
Please note that the above code is only for sending POST requests without files. If you need to send a POST request with files, you can use the ‘files’ parameter of the requests.post() function to specify the file path. For more information on how to use the requests library, please refer to the official documentation: https://docs.python-requests.org/en/latest/