• 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()类里面的函数调用
  • 相关阅读:
    发布镜像
    实战Tomcat镜像
    Docker File介绍
    数据卷容器
    DockerFile
    具名、匿名、指定路径挂载
    实战MySQL
    SHELL 常用技巧
    CentOS6和7启动流程
    解决服务器openssh漏洞
  • 原文地址:https://www.cnblogs.com/zhang-ping1205/p/12943940.html
Copyright © 2020-2023  润新知