from flask import Flask, request
app = Flask(__name__)
@app.route('/method', methods=['GET', 'POST'])
@app.route('/method/<wish>', 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)
curl --request POST \
--url https://postman-echo.com/post \
--data 'This is expected to be sent back as part of response body.'
响应:
{"args":{},"data":"","files":{},"form":{"This is expected to be sent back as part of response body.":""},"headers":{"host":"postman-echo.com","content-length":"58","accept":"*/*","content-type":"application/x-www-form-urlencoded","user-agent":"curl/7.54.0","x-forwarded-port":"443","x-forwarded-proto":"https"},"json":{"...
13 回答
有http://ptsv2.com/
只需自己设置一个 . 将此代码段复制到您的网络服务器 .
只需将您想要的内容发布到该页面即可 . 完成 .
nc one-liner local test server
在Linux下的一行中设置本地测试服务器:
另一个shell上的示例请求制定者:
然后在第一个shell上,您会看到显示的请求:
nc
在Ubuntu上广泛可用并预安装 .在Ubuntu 18.04上测试过 .
https://www.mockable.io . 它具有很好的功能,无需登录即可获得 endpoints (24小时临时帐户)
如果您希望本地测试服务器接受任何URL并将请求转储到控制台,则可以使用节点:
将其保存在文件'echo.js'中并按如下方式运行:
然后,您可以提交数据:
它将显示在服务器的标准输出中:
Webhook Tester是一个很棒的工具:https://webhook.site(GitHub)
对我来说很重要,它显示了请求者的IP,当您需要将IP地址列入白名单但不确定它是什么时,它会很有用 .
http://requestb.in 与已经提到的工具类似,也有一个非常好的用户界面 .
虽然它已于2018年3月21日停产 .
我已经创建了一个开源的hackable本地测试服务器,您可以在几分钟内运行 . 您可以创建新的API,定义自己的响应并以您希望的任何方式进行攻击 .
Github Link :https://github.com/prabodhprakash/localTestingServer
创建选择一个免费的Web主机并输入以下代码
我不确定是否有人会花这么多痛苦来测试GET和POST调用 . 我使用了Python Flask模块并编写了一个类似于@Robert共享的函数 .
当我运行这个时,会出现以下情况:
Now lets try some calls. I am using the browser.
http://127.0.0.1:5000/method
这只是一个GET方法
http://127.0.0.1:5000/method/NotCorrect
这个愿望不可用 . 以下是可用的愿望:['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']
http://127.0.0.1:5000/method/environ
{'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'}
http://httpbin.org/
它回应了您的请求中使用的任何这些类型的数据:
http://httpbin.org/ip返回原始IP .
http://httpbin.org/user-agent返回用户代理 .
http://httpbin.org/headers返回标头字典 .
http://httpbin.org/get返回GET数据 .
http://httpbin.org/post返回POST数据 .
http://httpbin.org/put返回PUT数据 .
http://httpbin.org/delete返回DELETE数据
http://httpbin.org/gzip返回gzip编码数据 .
http://httpbin.org/status/:code返回给定的HTTP状态代码 .
http://httpbin.org/response-headers?key=val返回给定的响应标头 .
http://httpbin.org/redirect/:n 302重定向n次 .
http://httpbin.org/relative-redirect/:n 302相对重定向n次 .
http://httpbin.org/cookies返回cookie数据 .
http://httpbin.org/cookies/set/:name/:value设置一个简单的cookie .
http://httpbin.org/basic-auth/:user/:passwd挑战HTTPBasic Auth .
http://httpbin.org/hidden-basic-auth/:user/:passwd 404'd BasicAuth .
http://httpbin.org/digest-auth/:qop/:user/:passwd挑战HTTP摘要验证 .
http://httpbin.org/stream/:n Streams n-100行 .
http://httpbin.org/delay/:n延迟响应n-10秒 .
这是一个邮差回声:https://docs.postman-echo.com/
例:
响应:
看看PutsReq,它与其他类似,但它也允许您使用JavaScript编写所需的响应 .