Skip to content

Commit c6ee4fa

Browse files
committed
modify post request demo
1 parent 12d2c7c commit c6ee4fa

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

RequestsDemo/request.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ case3
6262
${body} Get Dictionary Items ${responsedata}
6363
${body} Get Dictionary Values ${responsedata}
6464
${str} Get From Dictionary ${responsedata} pass
65+
66+
case4
67+
#用户密码
68+
${dict} Create Dictionary Content-Type=application/x-www-form-urlencoded
69+
Create Session api http://localhost:8000 ${dict}
70+
${data} Create Dictionary username=qitao password=qt
71+
${addr} post Request api /post data=${data}
72+
Comment Should Be Equal As Strings ${addr.status_code} 200
73+
log ${addr.content}
74+
log ${addr.json()}
75+
${responsedata} to json ${addr.content}
76+
${body} Get Dictionary Keys ${responsedata}
77+
${body} Get Dictionary Items ${responsedata}
78+
${body} Get Dictionary Values ${responsedata}
79+
${str} Get From Dictionary ${responsedata} username

demo-website/flaskdemo.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def output_xml(data, code, headers=None):
2727
app = Flask(__name__)
2828
db = Dao()
2929

30-
api = Api(app, default_mediatype='application/xml')
30+
api = Api(app, default_mediatype='application/json')
3131
api.representations['application/xml'] = output_xml
3232

3333

@@ -153,33 +153,13 @@ def getlist():
153153
#print ret_data
154154
return jsonify(AllProducts=ret_data)
155155

156-
@app.route('/api/<userid>', methods=['GET','POST'])
157-
def webapi(userid):
156+
@app.route('/post', methods=['POST','GET'])
157+
def webapi():
158158
message = None
159159

160-
if request.methods == 'POST':
161-
if request.headers['Content-Type'] == 'text/plain':
162-
return "Text Message: " + request.data
163-
164-
elif request.headers['Content-Type'] == 'application/json':
165-
return "JSON Message: " + json.dumps(request.json)
166-
167-
elif request.headers['Content-Type'] == 'application/octet-stream':
168-
f = open('./binary', 'wb')
169-
f.write(request.data)
170-
f.close()
171-
return "Binary message written!"
172-
173-
else:
174-
return "415 Unsupported Media Type ;)"
175-
176-
177-
elif request.methods == 'GET':
178-
users = {'1':'john', '2':'steve', '3':'bill'}
179-
if str(userid) in users:
180-
return jsonify({userid:users[userid]})
181-
else:
182-
return not_found()
160+
if request.method == 'POST':
161+
message = request.form['username']
162+
return jsonify({'username':message})
183163

184164
#print ret_data
185165
return None

0 commit comments

Comments
 (0)