http协议及Requests主要方法

1、HTTP协议(超文本传输协议)

  1.1、http协议是一个基于“请求与响应”模式的、无状态的应用层协议。

    http协议采用URL作为定位网络资源的标识。

  1.2、URL格式 http://host[:port][path]

    host:合法的Internet主机域名或IP地址

    port:端口号,缺省端口为80

    path:请求资源的路径

      e.http://www.baidu.com

    URL是通过http协议存取资源的Internet路径。一个URL对应一个数据资源。

  1.3、http协议对资源的操作

    get:获取URL位置资源

    head:获取URL位置资源头部信息

    post:向URL位置资源增加信息

    put:覆盖原来URL位置资源

    patch:修改URL位置资源

    delete:删除URL位置资源

2、Requests库

  2.1、方法与http协议对资源操作对应

  request方法

requests.request(method,url,**kwargs)
#method:请求方式,对应get/put/post等7种
#url:url链接
r=requests.request('GET',url,**kwargs)
r=requests.request('HEAD',url,**kwargs)
r=requests.request('POST',url,**kwargs)
r=requests.request('PUT',url,**kwargs)
r=requests.request('PATCH',url,**kwargs)
r=requests.request('delete',url,**kwargs)
r=requests.request('OPTIONS',url,**kwargs)  #获取服务器中相关参数

#**kwargs
#params 添加部分参数,放在url连接中
#data  向服务器提交资源
#json  json格式数据,提交内容
#headers  定制访问某个url的协议头
#cookies  
#auth  
#files  传输文件字段
#timeout  设定超时时间
#proxies  字典类型 代理服务器 隐藏原IP地址
#allow_redirects  True/False, 默认为True,重定向开关
#stream  True/False, 默认为True,获取内容立即下载开关
#vreify  True/False, 默认为True,认证SSL证书开关
#cert  本地SSL证书路径

  get方法

requests.get(url,params=None,**kwargs)
#params  添加部分额外参数,放在url连接中
#**kwargs  除了params以外其他12个

  head方法

requests.head(url,**kwargs)

  post方法

requests.head(url,data=None,json=None,**kwargs)

  put方法

requests.head(url,data=None,**kwargs)

  patch方法

requests.head(url,data=None,**kwargs)

  delete方法

requests.head(url,**kwargs)

  常用参数给出

原文地址:https://www.cnblogs.com/oldhuang/p/10319761.html