Python通过requests模块发送GET,POST请求
GET 请求示例(片段)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import requests import sys import codecs from t import payload sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
class body(object): def __init__(self):
self.headers = { 'Connection':'keep-alive', 'content-type':'application/json', 'Accept-Encoding':'gzip,deflate,br', 'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat', 'Referer':'', 'cookie':'' }
def prt_err_msg(self, res, expectation): if res['code'] != expectation: print('ERROR:', res['message']) else: print('SUCCESS')
def get(self):
api = ''
res = requests.get(url, headers=self.headers, data=payload.encode('utf-8')).json() self.prt_err_msg(res, 0)
def run(self):
print('get check') self.sign()
|
请求示例(片段)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import requests import sys import codecs from t import payload sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
class wx(object): def __init__(self):
self.headers = { 'Host':'', 'Connection':'keep-alive', 'X-Tag':'', 'Content-Length':'', 'content-type':'application/json', 'Accept-Encoding':'gzip,deflate,br', 'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat', 'Referer':'', 'cookie':'' }
def prt_err_msg(self, res, expectation): if res['code'] != expectation: print('ERROR:', res['message']) else: print('SUCCESS')
def sign(self):
url = ""
res = requests.post(url, headers=self.headers, data=payload.encode('utf-8')).json() self.prt_err_msg(res, 0)
def run(self):
print('ck') self.sign()
|
SCF 传入
index.main_handler