# 接口测试文件
import http.client
import json
# 测试程序执行入口
def test_server(json_data, port, host='127.0.0.1', url="/"):
headers = {
'Content-Type': 'application/json', # 指定内容类型为JSON
}
try:
http_conn = http.client.HTTPConnection(host, port, timeout=30000)
http_conn.request('POST', url, body=json_data.encode('utf-8'), headers=headers)
response = http_conn.getresponse()
recv = response.read().decode('utf-8') # 将响应数据解码为字符串
http_conn.close()
print("响应数据:", recv)
return recv
except Exception as e:
print("发生错误:", e)
09-19
1885
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-30
689
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)