簡體   English   中英

HTTP POST 請求/響應

[英]HTTP POST request/response

當我發出 POST 請求時,如何訪問鍵的值(成功)我嘗試了以下操作

    @app.route('/register', methods=['GET','POST'])
 def vid():
 if request.method == "POST":
  firstname=request.form['firstname']
  lastname=request.form['lastname']
  email=request.form['email']
  gender=request.form['gender']
  phone=request.form['mobileno']
  city=request.form['city']
  dob=request.form['dob']
  qualification=request.form['qualification']
  marital=request.form['marital']
  occupation=request.form['occupation']
  logintype=request.form['logintype']
  password=request.form['password']
  redemptionmode=request.form['redemptionmode']
  headers={'X-AUTH': 'GJTREWFRBN8675'}
  inputs={'firstname': firstname , 'lastname': lastname,'email': email,'gender': 
   gender,'mobile':phone, 'city': city,
  'dob': dob,'education': 
  occupation,'maritalstatus':marital,'occupation':occupation,'logintype':'local','password':password,
  'redemptionmode': redemptionmode}
  r = requests.post('https://api.imaginedreality.in/api/signup',headers=headers,data=inputs)
  
  if r.success == "true":
     #some operation#
  else 
     #some operations#

''' 收到錯誤“object 響應沒有屬性成功”但是有一個名為成功鋤頭的鍵我可以訪問它的值嗎?

這是理想的反應

{"success": "true","data": { },"message": "Signup Success"}

您必須使用將其轉換為json來獲取數據刪除 if-else 並且您可以編寫如下。

r = r.json()

if(r['success'] == 'true'):
    # Some operation
else:
    # Some operation

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM