温馨提示×

python中怎么用post提交数据

小亿
88
2024-03-06 12:02:58
栏目: 编程语言

在Python中使用post方法提交数据,通常使用requests库。以下是一个简单的例子:

import requests

url = 'https://www.example.com/api'
data = {'key1': 'value1', 'key2': 'value2'}

response = requests.post(url, data=data)

print(response.text)

在这个例子中,我们使用requests库发送一个post请求到指定的url,并传递一个包含键值对的字典作为数据。提交的数据可以是表单数据、JSON数据等。接收到的响应可以通过response.text来获取。

0