zoukankan      html  css  js  c++  java
  • 从接口自动化测试框架设计到开发(七)--cookie处理

    模拟登陆获取cookie

    # -*- coding: utf-8 -*-
    # @Author: jiujiu
    # @Date:   2020-03-09 17:05:13
    # @Last Modified time: 2020-03-09 17:37:03
    import requests
    import json
    url = "http://10.1.30.118:3200/provider/user/user/login"
    data = {
        'loginName':'15519560000',
        'loginModel':'0',
        'password':'12345678',
        'loginType':'01',
        'timeStamp':'1582616038764'
        }
    res = requests.post(url,data).json()
    json.dumps(res,sort_keys=True,indent=10)
    print(res['data']['token'])

    运行结果

     简单的通过登录获取token,再通过添加token get到数据

    # -*- coding: utf-8 -*-
    # @Author: jiujiu
    # @Date:   2020-03-09 17:05:13
    # @Last Modified time: 2020-03-11 15:38:42
    import requests
    import json
    def login():
            url = "http://10.1.30.119:9005/user/login"
            data = {
                'loginName': '012345',
                'password': '123456',
                'loginType': '01',
                'loginModel': '0',
                'anti_cache': '1583909753278'
                }
            res = requests.post(url,data=data).json()
                # json.dumps(res,sort_keys=False,indent=1,ensure_ascii=False)
                # token = res['data']['token']
    #token = requests.utils.dict_from_cookiejar(token)
            # print(res)
            token = res['data']['token']
            # print(token)
            return token
    login()
    
    def get_data():
        print({'token':login()})
        url = "http://10.1.30.119:9005/query/selectDriverInfo?current=1&size=20&total=18&car_type=%E5%A4%A7%E5%9E%8B%E5%AE%A2%E8%BD%A6&sex=&time=&screenFiled=&deal_time_s=&deal_time_e=&anti_cache=1583909895350"
        header = {
        'token':login()
        }
        res = requests.get(url=url,headers=header)
        print(res.text)
    if __name__ == '__main__':
        get_data()

    运行结果:

  • 相关阅读:
    HTMLDOM
    换行
    【iOS】APP之数据存储
    开启远程XUL
    iOS之Streams
    Plugin的生命周期
    ActiveX Control Test Container
    ObjectiveC Runtime III【objc_msgSend函数】
    What is a Digital Signature?
    JS变量作用域
  • 原文地址:https://www.cnblogs.com/dydxw/p/12449958.html
Copyright © 2011-2022 走看看