Python class 模拟GET POST JSON   请求 源代码

42b50efa636f056c8d8d800b98b0eda2

Python常用的几个请求方式 GET POST JSON   调用方法 jk(1,url,data,headers)

class jk:
    "请求数据"
    def __init__(self,id,url,data,headers):
        self.id=id
        self.url=url
        self.data=data
        self.headers=headers
    def get(self):
        r = requests.get(url=self.url, headers=self.headers,  timeout=5)
        r.encoding = r.apparent_encoding
        print(r.json(), '\n请求代码:{}'.format(r.status_code))

    def post(self):
        r = requests.post(url=self.url, data=self.data, headers=self.headers,  timeout=5)
        r.encoding = r.apparent_encoding
        print(r.json(), '\n请求代码:{}'.format(r.status_code))

    def json(self):
        r = requests.post(url=self.url, json=self.data, headers=self.headers,  timeout=5)
        r.encoding = r.apparent_encoding
        print(r.json(), '\n请求代码:{}'.format(r.status_code))

 

THE END