HTTP test server accepting GET/POST requests

2019-01-03 00:24发布

I need a live test server that accepts my requests for basic information via HTTP GET and also allows me to POST (even if it's really not doing anything). This is entirely for test purposes.

A good example is here. It easily accepts GET requests, but I need one that accepts POST requests as well.

Does anyone know of a server that I can send dummy test messages too?

标签: http post
13条回答
小情绪 Triste *
2楼-- · 2019-01-03 00:51

I am not sure if anyone would take this much pain to test GET and POST calls. I took Python Flask module and wrote a function that does something similar to what @Robert shared.

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"

When I run this, this follows:

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.

http://127.0.0.1:5000/method

This is just a GET method

http://127.0.0.1:5000/method/NotCorrect

This wish is not available. The following are the available wishes: ['application', 'args', 'authorization', 'blueprint', 'charset', 'close', 'cookies', 'data', 'date', 'endpoint', 'environ', 'files', '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': False, 'HTTP_COOKIE': 'csrftoken=YFKYYZl3DtqEJJBwUlap28bLG1T4Cyuq', 'SERVER_SOFTWARE': 'Werkzeug/0.12.2', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/method/environ', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING': '', 'werkzeug.server.shutdown': , 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like 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': '127.0.0.1', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, sdch, br'}

查看更多
叼着烟拽天下
3楼-- · 2019-01-03 00:55

Have a look at PutsReq, it's similar to the others, but it also allows you to write the responses you want using JavaScript.

查看更多
神经病院院长
4楼-- · 2019-01-03 00:55

Webhook Tester is a great tool: https://webhook.site (GitHub)

enter image description here

Important for me, it showed the IP of the requester, which is helpful when you need to whitelist an IP address but aren't sure what it is.

查看更多
干净又极端
5楼-- · 2019-01-03 00:56

Here is one Postman echo: https://docs.postman-echo.com/

example:

curl --request POST \
  --url https://postman-echo.com/post \
  --data 'This is expected to be sent back as part of response body.'

response:

{"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":{"...
查看更多
走好不送
6楼-- · 2019-01-03 00:58

There is http://ptsv2.com/

"Here you will find a server which receives any POST you wish to give it and stores the contents for you to review."

查看更多
▲ chillily
7楼-- · 2019-01-03 00:58

Just set one up yourself. Copy this snippet to your webserver.


echo "<pre>";
print_r($_POST);
echo "</pre>";

Just post what you want to that page. Done.

查看更多
登录 后发表回答