发请求:
def test_url(method, url, param=''):
#HOST, PORT = "0.0.0.0", 8500
HOST, PORT = "0.0.0.0", 51256
conn = http.client.HTTPConnection(HOST, PORT)
conn.connect()
param = json.dumps(param)
conn.request(method, url, param, header)
print("request")
buf = conn.getresponse()
result = buf.read()
print(result)
conn.close()
接收参数:
@offer.route("/jupiterapi/offer/add",methods = ["POST"])
def add_offer():
res = {"code":404,"data":"","msg":""}
param = dict(request.args.items()) #从url获取请求参数:类型是一个生成器对象(<class 'geterator'>)
print(param)
print(type(param))
print("------------------------------------")
options = request.get_json() #post方法提交从param获取请求参数:get_json()方法获取的是dict类型
print(type(options))
for k,v in options.items():
print(k,v)
return jsonify(res)