zoukankan      html  css  js  c++  java
  • http client sample(json+md5) in python

    1、client

    1) httpie

    http -f POST example.org hello=World

    http POST http://192.168.200.251:55101/Api/Client/Login? Account=zdd_1 Password=0192023a7bbd73250516f069df18b500 DeviceCode=20190806 > file

    login.json

    {
      "Account": "zdd_1",
      "Password": "0192023a7bbd73250516f069df18b500",
      "DeviceCode": "20190806"
    }

    http POST http://192.168.200.251:55101/Api/Client/Login?/login.json @$(pwd)/login.json

    2) python requests

    复制代码
    import requests
    import json
    import datetime
    import time
    from hashlib import md5
    
    #global var
    url_base = 'http://192.168.200.251:55101'
    account = "zdd_1"
    passwd = "admin123"
    device_code = "20190806"
    
    #timeStamp
    get_now_milli_time = lambda: int(time.time() * 1000)
    
    #md5
    def encrypt_md5(s):
        new_md5=md5()
        new_md5.update(s.encode(encoding='utf-8'))
        return new_md5.hexdigest()
    
    
    ########################################################
    
    # login 
    url = url_base + '/Api/Client/Login?'
    login = {
      "Account": "",
      "Password": "",
      "DeviceCode": ""
    }
    
    
    login['Account'] = account
    login['Password'] = encrypt_md5(passwd)
    login['DeviceCode'] = device_code
    
    r = requests.post(url, data = login)
    print(r.status_code)
    print(r.text)
    d = json.loads(r.text)
    print(d['Code'])
    token = d['Result']['Token']
    ID = d['Result']['Id']
    print(token)
    print(ID)
    
    ########################################################
    
    # get reg info
    url = url_base + '/Api/Client/GetDeviceRegister?'
    get_reg_info = {
      "code": "20190806",
      "ssoToken": "",
      "stationId": "",
      "timeStamp": "",
      "accessSignature": ""
    }
    
    get_reg_info['ssoToken'] = token
    get_reg_info['timeStamp'] = str(get_now_milli_time()) 
    get_reg_info['stationId'] = ""
    get_reg_info['code'] = device_code
    s1 = encrypt_md5(get_reg_info['timeStamp']).upper()
    print(s1)
    s2 = encrypt_md5(ID + s1).upper()
    print(s2)
    get_reg_info['accessSignature'] = s2
    r = requests.get(url,params=get_reg_info)
    print(r.status_code)
    print(r.text)
    d = json.loads(r.text)
    print(d)
    复制代码
  • 相关阅读:
    [一个经典的多线程同步问题]解决方案二:Event事件
    [进程与线程]进程、线程的生活
    从C++strStr到字符串匹配算法
    Dubbo 服务集群容错配置
    TCP三次握手
    zookeeper 学习 客户端Acl操作笔记
    ubuntu下的“用vim打开中文乱码,用cat打开正常显示”的解决方法
    JDK1.7 Update14 HotSpot虚拟机GC收集器
    账户信息不存在的问题
    win10 64 使用 visual studio 2017 搭建汇编开发环境
  • 原文地址:https://www.cnblogs.com/dong1/p/5240598.html
Copyright © 2011-2022 走看看