PostMan 概述 PostMan是常用的http接口测试工具,无论是开发人员进行接口调试,还是测试人员做接口测试,postman都是首选工具之一 。PostMan是一款支持http协议的接口调试与测试工具,其主要特点就是功能强大,使用简单且易用性好 。相较于PostMan,还有一些国内的竞品软件如APIPost、APIPost7等、简单的进行接口测试其实都没有太大差别。
使用方法 使用PostMan测试POST接口(不带参数)
使用PostMan测试POST接口(带参数)
注意事项
当前软件仅在测试或者少量查询中使用,如果是批量查询,请使用脚本。
当请求API存在高并发现象,可以使用多线程进行处理。
脚本调用API 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 import jsonimport requestsapi_brief = 'detection_detail' domin = "https://open-source.vulgraph.net:8000" token = "" paramPath = r'C:\Users\Administrator\Desktop\param.txt' api_path = '' def readDoc4API (): """ 读取文件获取全部API列表 :return: API List """ api_list = [] with open (api_path, 'r' , encoding='utf-8' ) as f: while True : data = f.readline() if not data: break else : if len (data) == 0 : continue if len (data.split('\t' )) == 2 and data.__contains__('/' ): api_list.append(data.split('\t' )[0 ]) return api_list def getParam (): """ 读取参数 :return: 参数列表 """ with open (paramPath, 'r' , encoding='utf-8' ) as f: data = f.read() return json.loads('' .join(data)) def apiRequest (domin, token, params, path ): """ 请求API获取结果 :param domin: 网站域名 :param token: 用户Token :param params: 其他参数 :param path: url的请求路径 :return: None """ headers = { "userToken" : f"{token} " } body = params try : url = domin + path print ("请求的url为:" , url) response = requests.post(url, headers=headers, data=json.dumps(body)) response.raise_for_status() data = response.json() return data except requests.exceptions.RequestException as e: print ("请求发生错误:" , e) return None def execute (): """ 执行代码 :return: None """ global path api_list = readDoc4API() params = getParam() for i in api_list: if i.__contains__(api_brief): path = i for param in params: response_data = apiRequest(domin, token, param, path) if response_data: print (response_data) with open ('./res.txt' , 'a' , encoding='utf-8' ) as f: f.write(json.dumps(response_data['data' ]) + '\n' ) if __name__ == '__main__' : execute()