# -*- coding: utf-8 -*-
import json
import requests



headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'gzip',
'Connection': 'close',
'Referer': None
}

# 自定义类
class MyClass:
# 初始化
def __init__(self):
print("__init__=====>self: " , "self")

# 创建MyClass对象
myClass = MyClass()
# 对象转化为字典
myClassDict = myClass.__dict__
# 字典转化为json
myClassJson = json.dumps(myClassDict,sort_keys=True, indent=2,ensure_ascii=False)
myClassLoads = json.loads(myClassJson)


def reqSend(obj, url,log):
try:
myClassDict = obj.__dict__
myClassJson = json.dumps(myClassDict, sort_keys=True, indent=2, ensure_ascii=False)
myClassLoads = json.loads(myClassJson)
r1 = requests.post(url, data=myClassLoads, headers=headers)
r1.encoding = 'utf-8'
log.warn("***执行接口>>>>>"+url+'\n【请求参数】\n'+myClassJson)
r1Text = json.dumps(json.loads(r1.text),sort_keys=True, indent=2,ensure_ascii=False)
log.debug('【响应】\n'+r1Text)
return r1Text;
except:
print("reqSend=====>except: " , "except")
pass
posted on 2018-06-28 17:03  天之城  阅读(136)  评论(0编辑  收藏  举报