需求:向不同IP地址的服务分发请求
思路:在URL中添加一个参数IP地址,提取出来之后,向这个地址转发
@app.route('/getDeviceInf',methods=['GET','POST'])
def getDeviceInf(): # put application's code here
ConfigServerIP = request.args.get("ConfigServerIP")
# 发送GET请求
response = requests.get(f'http://{ConfigServerIP}:4119/api/pecnode/v1/device/tree?parentNodeType=269619456', request.json)
# 校验状态码
# assert response.status_code == 201
# 校验返回的json
# assert response.json()['title'] == 'foo'
print(ConfigServerIP)
print("POST request test passed.")
# return 'Hello World!'
return response.json()