1 requests 常用请求方法
get请求采用requests.get()方法,一般用于从服务器获取响应内容
post请求采用requests.post()方法,一般用于上传内容到服务器
2 requests 常用请求参数
get请求(如果需要传参,参数需要通过params传入,会显示拼接在URL里边)
import requests
res1 = requests.get("https://www.baidu.com")
print(res1.content)
res2 = requests.get("http://httpbin.org/get",params={"key1":"value1","key2":"value2"})
print(res2.url) # http://httpbin.org/get?key1=value1&key2=value2
post请求(参数需要通过data传入,不会显示在URL里边)
post请求一般用于登陆注册,对请求的长度没有要求限制
res3 = requests.post("http://httpbin.org/get",data={"key":"value"})
print(res3.url)