python中HTTP方法有哪些

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基础教程

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。