首页 文章

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

提问于
浏览
354

我需要一个实时测试服务器,它通过HTTP GET接受我对基本信息的请求,并允许我POST(即使它真的没有做任何事情) . 这完全用于测试目的 .

一个很好的例子是here . 它很容易接受GET请求,但我也需要一个接受POST请求的请求 .

有没有人知道我可以发送虚拟测试消息的服务器?

13 回答

  • 1

    http://ptsv2.com/

    “在这里,您将找到一个服务器,它接收您希望提供的任何POST并存储内容供您查看 . ”

  • 7

    只需自己设置一个 . 将此代码段复制到您的网络服务器 .

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

    只需将您想要的内容发布到该页面即可 . 完成 .

  • 2

    nc one-liner local test server

    在Linux下的一行中设置本地测试服务器:

    while true; do printf '' | nc -l localhost 8000; done
    

    另一个shell上的示例请求制定者:

    wget http://localhost:8000
    

    然后在第一个shell上,您会看到显示的请求:

    GET / HTTP/1.1
    User-Agent: Wget/1.19.4 (linux-gnu)
    Accept: */*
    Accept-Encoding: identity
    Host: localhost:8000
    Connection: Keep-Alive
    

    nc 在Ubuntu上广泛可用并预安装 .

    在Ubuntu 18.04上测试过 .

  • 1

    https://www.mockable.io . 它具有很好的功能,无需登录即可获得 endpoints (24小时临时帐户)

  • 91

    如果您希望本地测试服务器接受任何URL并将请求转储到控制台,则可以使用节点:

    const http = require("http");
    
    const hostname = "0.0.0.0";
    const port = 3000;
    
    const server = http.createServer((req, res) => {
      console.log(`\n${req.method} ${req.url}`);
      console.log(req.headers);
    
      req.on("data", function(chunk) {
        console.log("BODY: " + chunk);
      });
    
      res.statusCode = 200;
      res.setHeader("Content-Type", "text/plain");
      res.end("Hello World\n");
    });
    
    server.listen(port, hostname, () => {
      console.log(`Server running at http://localhost:${port}/`);
    });
    

    将其保存在文件'echo.js'中并按如下方式运行:

    $ node echo.js
    Server running at http://localhost:3000/
    

    然后,您可以提交数据:

    $ curl -d "[1,2,3]" -XPOST http://localhost:3000/foo/bar
    

    它将显示在服务器的标准输出中:

    POST /foo/bar
    { host: 'localhost:3000',
      'user-agent': 'curl/7.54.1',
      accept: '*/*',
      'content-length': '7',
      'content-type': 'application/x-www-form-urlencoded' }
    BODY: [1,2,3]
    
  • 5

    Webhook Tester是一个很棒的工具:https://webhook.siteGitHub

    enter image description here

    对我来说很重要,它显示了请求者的IP,当您需要将IP地址列入白名单但不确定它是什么时,它会很有用 .

  • 35

    http://requestb.in 与已经提到的工具类似,也有一个非常好的用户界面 .

    RequestBin为您提供一个URL,用于收集对其发出的请求,并让您以人性化的方式检查它们 . 使用RequestBin查看HTTP客户端正在发送的内容或检查和调试webhook请求 .

    虽然它已于2018年3月21日停产 .

    由于持续滥用,我们已停止公开托管的RequestBin版本,因此很难确保网站的可靠性 . 请参阅有关设置自己的自托管实例的说明 .

  • 27

    我已经创建了一个开源的hackable本地测试服务器,您可以在几分钟内运行 . 您可以创建新的API,定义自己的响应并以您希望的任何方式进行攻击 .

    Github Linkhttps://github.com/prabodhprakash/localTestingServer

  • 17

    创建选择一个免费的Web主机并输入以下代码

    <h1>Request Headers</h1>
     <?php
     $headers = apache_request_headers();
    
     foreach ($headers as $header => $value) {
         echo "<b>$header:</b> $value 
    \n"; } ?>
  • 3

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

    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)
    

    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'}

  • -13

    http://httpbin.org/

    它回应了您的请求中使用的任何这些类型的数据:

  • 2

    这是一个邮差回声:https://docs.postman-echo.com/

    例:

    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":{"...
    
  • 616

    看看PutsReq,它与其他类似,但它也允许您使用JavaScript编写所需的响应 .

相关问题