import requests
url='http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz'
data={
'ajax' :1,
'email' :'admin',
'user_pwd' :'cGdWWURWa0RGemlYRm1rcm5icnlJVlVDeXdDcHFaTXRMb0dERUhZSndleGpxSmRBYWYlMjV1NjVCOSUyNXU3RUY0YWRtaW4lMjV1OEY2RiUyNXU0RUY2'
}
header={
'Host':'106.52.182.140',
'X-Requested-With':'XMLHttpRequest',
'Origin':'http://106.52.182.140',
'Referer': 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
}
rq = requests.post(url=url,data=data,headers=header)
hd = rq.headers
print(hd)
set_cookie = hd['Set-Cookie']
print(set_cookie)
cookie=set_cookie.split(';',1)[0]
print(cookie)
url2 ='http://106.52.182.140/fanwe/member.php?ctl=uc_account&act=save'
data2={
'address':'中国北京市宜章李田龙溪村一组',
'avatar_file':'',
'city_id':'52',
'commit':'保存更改',
'graduation':'本科',
'marriage':'未婚',
'phone' :'0735-17674124567',
'province_id':'2',
'university':'北京大学'
}
header2 = {
'Host': '106.52.182.140',
'Connection':'keep-alive',
'Content-Length': '361',
'Cache-Control':'max-age=0',
'Upgrade-Insecure-Requests': '1',
'Origin':'http://106.52.182.140',
'Content-Type':'application/x-www-form-urlencoded',
'Referer':'http://106.52.182.140/fanwe/member.php?ctl=uc_account',
'Cookie':cookie
}
rq = requests.post(url=url2,headers=header2,data=data2)
print(rq.text[315:345])
python操作requests
做接口自动化一般使用到request是模块,python有很强大的模块
```python
import requests
url='http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=ZsZUlUILQjqxGLkopRAdEsyPBmdcjONCWRZXfEuuKawHzjKkBz'
data={
'ajax' :1,
'email' :'admin',
'user_pwd' :'cGdWWURWa0RGemlYRm1rcm5icnlJVlVDeXdDcHFaTXRMb0dERUhZSndleGpxSmRBYWYlMjV1NjVCOSUyNXU3RUY0YWRtaW4lMjV1OEY2RiUyNXU0RUY2'
}
header={
'Host':'106.52.182.140',
'X-Requested-With':'XMLHttpRequest',
'Origin':'http://106.52.182.140',
'Referer': 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
}
rq = requests.post(url=url,data=data,headers=header)
hd = rq.headers
print(hd)
set_cookie = hd['Set-Cookie']
print(set_cookie)
cookie=set_cookie.split(';',1)[0]
print(cookie)
url3 ='http://106.52.182.140/fanwe/member.php?ctl=uc_account&act=save'
data2={
'address':'中国上海宜章李田龙溪村一组',
'avatar_file':'',
'city_id':'52',
'commit':'保存更改',
'graduation':'高中',
'marriage':'已婚',
'phone' :'0735-17864124567',
'province_id':'2',
'university':'清华大学'
}
header2 = {
'Host': '106.52.182.140',
'Connection':'keep-alive',
'Content-Length': '361',
'Cache-Control':'max-age=0',
'Upgrade-Insecure-Requests': '1',
'Origin':'http://106.52.182.140',
'Content-Type':'application/x-www-form-urlencoded',
'Referer':'http://106.52.182.140/fanwe/member.php?ctl=uc_account',
'Cookie':cookie
}
rq = requests.post(url=url3,headers=header2,data=data2)
print(rq.text[315:345])