import json
import requests
res=requests.get(“http://www.baidu.com”)
print(res.headers)
print(res.content)
print(res.content.decode(encoding= “utf-8”))
print(res.status_code)
//自动解码,有概率出错
print(res.text)
data={
“accounts”:“zz”,
“pwd”:“123456”,
“type”:“username”
}
url = " http://shop-xo.hctestedu.com/index.php?s=api/user/login"
gc={
“application”:“app”,
“application_client_type”:“weixin”
}
res=requests.post(url=url,json=data,params=gc)
print(res.content)
print(res.json())
json格式为字符串 res.json()返回字典
print(type(res.json()))
print(res.raw)
print(json.loads(res.content))
assert “登录成功” == res.json()[‘msg’]