zoukankan      html  css  js  c++  java
  • python_30期自动化【类的封装】

    import requests
    class HttpRequests:
    # def https_requests(login_url,data,http_method):#调用;提高复用性
    #     @staticmethod
    #     def https_requests(login_url, data, http_method='POST'):
          @classmethod
          def https_requests(cls,login_url, data, http_method='POST'):
        # def https_requests(self,login_url, data, http_method='POST'):
            # login_url = "http://www.tuling123.com/openapi/api"
            # data = {
            #     "key": "ec961279f453459b9248f0aeb6600bbe",
            #     "info": "你好"
            # }  # 字典格式,单独提出来,方便参数的添加修改等操作(二选一的方式)
            if http_method.upper()=='GET':
                res = requests.get(login_url, data)
            else:#执行的是post请求
                res = requests.post(login_url, data)
            print("post请求的json格式报文", res.json())
    login_url = "http://www.tuling123.com/openapi/api"
    data = {
            "key": "ec961279f453459b9248f0aeb6600bbe",
            "info": "你好"
        }  # 字典格式,单独提出来,方便参数的添加修改等操作
    HttpRequests().https_requests(login_url,data,'GET')#HttpRequests()类里面的函数调用
  • 相关阅读:
    ZOJ 2770 Burn the Linked Camp 差分约束
    作业04 一个简单的扑克牌游戏
    C++友元
    ZOJ 3645高斯消元
    CodeForces 55D 数位统计
    03类的设计和使用
    HDU 4522
    POJ 2559单调栈
    PL/SQL REPORT 开发模拟登陆
    修改报表心得
  • 原文地址:https://www.cnblogs.com/zhang-ping1205/p/12943940.html
Copyright © 2011-2022 走看看