1.编写代码对接口实现简单的测试
## -*- coding: utf-8 -*- import requests import json def keyword_pickup(str): data = { "String":str } url = 'http://127.0.0.1:5000/kwpu' headers = {'Content-Type': 'application/json'} response = requests.post(url=url, headers=headers, data=json.dumps(data)) res = json.loads(response.text).get('keyword') # print(res) return res def generalization(str): data = { "String": str } url = 'http://127.0.0.1:5000/gen' headers = {'Content-Type': 'application/json'} response = requests.post(url=url, headers=headers, data=json.dumps(data)) res = json.loads(response.text).get('gen') print(res)
对接口使用post方式提交编写def keyword_pickup(str)方法对http://127.0.0.1:5000/kwpu测试输入简单字符串输出关键词。