显示接受服务器,HTTP测试服务器接受GET / POST请求

我不确定是否有人会花这么多痛苦来测试GET和POST调用 . 我使用了Python Flask模块并编写了一个类似于@Robert共享的函数 .

from flask import Flask, request

app = Flask(__name__)

@app.route('/method', methods=['GET', 'POST'])

@app.route('/method/', methods=['GET', 'POST'])

def method_used(wish=None):

if request.method == 'GET':

if wish:

if wish in dir(request):

ans = None

s = "ans = str(request.%s)" % wish

exec s

return ans

else:

return 'This wish is not available. The following are the available wishes: %s' % [method for method in dir(request) if '_' not in method]

else:

return 'This is just a GET method'

else:

return "You are using POST"

当我运行这个时,会出现以下情况:

C:\Python27\python.exe E:/Arindam/Projects/Flask_Practice/first.py

* Restarting with stat

* Debugger is active!

* Debugger PIN: 581-155-269

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Now lets try some calls. I am using the browser.

这只是一个GET方法

这个愿望不可用 . 以下是可用的愿望:['application','args','authorization','blueprint','charset','close','cookies','data','date','endpoint','environ ','''','form','headers','host','json','method','mimetype','module','path','pragma','range','referrer', 'scheme','shallow','stream','url','values']

{'wsgi.multiprocess':虚假,'HTTP_COOKIE':'csrftoken=YFKYYZl3DtqEJJBwUlap28bLG1T4Cyuq','SERVER_SOFTWARE':'Werkzeug/0.12.2','SCRIPT_NAME':'', ' REQUEST_METHOD ': ' GET ', ' PATH_INFO ': ' /方法/ ENVIRON ', ' SERVER_PROTOCOL ': ' HTTP / 1.1 ', ' QUERY_STRING ': ' ', ' werkzeug.server.shutdown ': , ' HTTP_USER_AGENT ': '的Mozilla / 5.0(视窗NT 6.1; WOW64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 54.0.2840.71 Safari / 537.36 ', ' HTTP_CONNECTION ': ' keep-alive ', ' SERVER_NAME ': ' 127.0.0.1 ', ' REMOTE_PORT ': 49569, ' wsgi.url_scheme ': 'http', ' SERVER_PORT ': ' 5000 ', ' werkzeug.request ': , ' wsgi.input ': , ' HTTP_HOST ': ' 127.0.0.1:5000 ', ' wsgi.multithread ': False, ' HTTP_UPGRADE_INSECURE_REQUESTS ': ' 1 ', ' HTTP_ACCEPT ': ' text / html,application / xhtml xml,application / xml; q = 0.9,image / webp,/; q = 0.8 ', ' wsgi.version ': (1, 0), ' wsgi.run_once ': False, ' wsgi.errors ': ',mode 'w' at 0x0000000002042150>,'REMOTE_ADDR':52751 1,'HTTP_ACCEPT_LANGUAGE':'en-US,en;q=0.8','HTTP_ACCEPT_ENCODING':'gzip, deflate, sdch, br'}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值