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'] {}
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试