0
点赞
收藏
分享

微信扫一扫

python使用hTTP方法

Python中可以使用requests库来发送HTTP请求,其中包括GET、POST、PUT、DELETE等方法。下面是一个使用requests库发送HTTP请求的示例:

import requests



# 发送GET请求

response = requests.get('Example Domain')



# 发送POST请求

data = {'key1': 'value1', 'key2': 'value2'}

response = requests.post('Example Domain', data=data)



# 发送PUT请求

data = {'key1': 'value1', 'key2': 'value2'}

response = requests.put('Example Domain', data=data)



# 发送DELETE请求

response = requests.delete('Example Domain')

在上面的示例中,我们使用了requests库的get()post()put()delete()方法来发送HTTP请求,并将响应保存在response变量中。在发送POST和PUT请求时,我们还传递了一个data参数,用于指定请求体中的数据。

举报

相关推荐

0 条评论