
作用:http[GET][POST]获得参数
url:域名.com/xx?value=4value = request.args['value']value = request.args.get('value')
json传输"":""$.ajax({url:"/",type:'get',dataType:"text",data:{x:{ 'id':'02' },//发送的东西},success:function(data){//成功之后},error:function(jqXHR){alert("发生错误:"+ jqXHR.status);//错误}})data = request.args['x']#获得数据data1 = json.loads(data)#json读取id = data1["id"]name = data1["name"]
json传输"":""$.ajax({url:"/",type:'post',dataType:"text",data:{"title":"1",//发送的东西},success:function(data){//成功之后},error:function(jqXHR){alert("发生错误:"+ jqXHR.status);//错误}})#获得参数value = request.json['value']value = request.json.get('value')
# 接收body raw{"data":["a","b","c"]}import jsonfrom flask import Flask, jsonify, request@xxx.route("/xxx", methods=['POST'])def xxx():try:data = request.datadata = json.loads(data)doc = data['data']print(doc)return "ok"except Exception as e:print(e)return "fail"
# 接收XML#获得参数data = request.dataprint(data)dict = xml_to_dict2(data)# 处理返回预付单方法def xml_to_dict2(data):import xml.etree.ElementTree as ETxml_dict = {}data_dic = ET.fromstring(data)for item in data_dic:xml_dict[item.tag]=item.textreturn xml_dict
print(request.__dict__) # 直接打印request# 这是url# xxx.com?xx=1&aa=2&bb=3value1 = request.args['value']value2 = request.args.get('value')print("value1")print(value1)print("value2")print(value2)# 这是body的from-data形式有:KEY、VALUE、DESCRIPTIONvalue3 = request.json['value']value4 = request.json.get('value')print("value3")print(value3)print("value4")print(value4)# 这是body的raw的json形式# {"AA":"aa","BB":"bb"}value5 = request.from['value']value6 = request.from.get('value')print("value5")print(value5)print("value6")print(value6)data = request.args['x']#获得数据data1 = json.loads(data)#json读取id = data1["id"]name = data1["name"]
print("1:request.form")print(request.form)print("2:request.data")print(request.data)print("3:request.method")print(request.method)print("4:request.values")print(request.values)print("5:request.headers")print(request.headers)print("6:request.args")print(request.args)print("7:request.json")print(request.json)