#!/usr/bin/env python
# -*- coding:utf-8 -*-
importrequests
importre
importurllib3
frommockimportmock
'''
1.mock是mock一个方法的调用,让它返回指定内容
2.所以需要传入所需要mock的方法,以及该方法所需要的参数,还有mock的返回内容
3.在mock里面调用传入的方法即可,返回mock指定的内容
'''
defmock_post(mock_method,url,data,headers,mcok_data):
mock_method = mock.Mock(return_value=mcok_data)
res = mock_method(url,data,headers)
returnres
urllib3.disable_warnings()
host ='https://demo3.appiron.cn:30443'
url = host +'/emm-manager/login/login.do'
# print(url)
# r = requests.get(url='https://demo3.appiron.cn:30443/emm-manager/', verify=False)
# #print(r.cookies)
# r_cookies = requests.utils.dict_from_cookiejar(r.cookies)['JSESSIONID']
# #print(r_cookies)
# r_cookies_str = 'JSESSIONID=' + r_cookies
data = {
'strname':'secadmin',
'strpwd':'91,48,3,52,108,185,237,115'
}
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0',
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding':'gzip, deflate, br',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With':'XMLHttpRequest',
'Content-Length':'66',
# 'Cookie': r_cookies_str,
'Cookie':'JSESSIONID=FB7AEBBF1F4363D0EBF5B6EB416028F0',
'Connection':'keep-alive'
}
mock_data = headers
res = mock_post(requests.post,url,data,headers,mock_data)
print(res)
领取专属 10元无门槛券
私享最新 技术干货