本篇主要记录下使用python的requests模块发送post请求的实现代码.
#coding=utf-8import unittestimport requestsclass PostTest(unittest.TestCase): def setUp(self): host = 'https://httpbin.org/' endpoint = 'post' self.url = ''.join([host, endpoint]) def testPost(self): params = { 'show_env':'1'} json = { 'info': { 'show_env': '2', 'sex': 'nv'}, 'code': 200, 'a': 'hello', 'b': 'nihao', 'files' : { 'file': ('test.txt', 'hello')}, 'data': [{ 'name': 'zhangsan', 'id': '123'}, { 'name': 'lisi', 'id': '125'}], 'id': 1900 } r1 = requests.post(self.url,params=params,json=json) resp1 = r1.json() print(resp1) connect = resp1['headers']['Connection'] self.assertEqual(connect, 'close') def tearDown(self): passif __name__=='__main__': unittest.main()