品易云推流 关闭
文章详情页
文章 > Python基础教程 > python中HTTP方法有哪些

python中HTTP方法有哪些

头像

小妮浅浅

2021-05-31 09:34:112233浏览 · 0收藏 · 0评论

1、除了 GET 之外,其他流行的HTTP方法包括 POST ,``PUT,DELETE,HEAD,PATCH和OPTIONS。requests为每个HTTP方法提供了一个方法,与get()具有类似的结构:

>>> requests.post('https://httpbin.org/post', data={'key':'value'})
>>> requests.put('https://httpbin.org/put', data={'key':'value'})
>>> requests.delete('https://httpbin.org/delete')
>>> requests.head('https://httpbin.org/get')
>>> requests.patch('https://httpbin.org/patch', data={'key':'value'})
>>> requests.options('https://httpbin.org/get')

2、每种方法的响应中都会返回头部,响应正文,状态码等。 调用每个函数使用相应的HTTP方法向httpbin服务发出请求。 对于每种方法,你可以像以前一样查看其响应:

>>> response = requests.head('https://httpbin.org/get')
>>> response.headers['Content-Type']
'application/json'
 
>>> response = requests.delete('https://httpbin.org/delete')
>>> json_response = response.json()
>>> json_response['args']
{}

以上就是python中HTTP方法的介绍,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图