我需要一个实时测试服务器,它通过HTTP GET接受我对基本信息的请求,并允许我POST(即使它真的什么都不做)。这完全是为了测试目的。

这里有一个很好的例子。它很容易接受GET请求,但我需要一个接受POST请求以及。

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


当前回答

我不知道为什么这里所有的答案都让一个很简单的工作很辛苦!

当HTTP上有一个请求时,实际上客户端会发送一个HTTP_MESSAGE到服务器(阅读HTTP_MESSAGE是什么),你可以用2个简单的步骤创建一个服务器:

安装netcat: 在许多基于unix的系统中,你已经安装了这个,如果你有windows只是谷歌它,安装过程真的很简单,你只需要一个nc.exe文件,然后你应该复制这个nc.exe文件的路径到你的path环境变量,并检查nc -h是否一切正常 创建一个监听localhost:12345的服务器: 只要在你的终端上输入nc -l -p 12345,一切就完成了!(在mac nc -l 12345 tnx Silvio Biasiol)


现在你有一个服务器在http://localhost:12345上监听,例如,如果你是一个js开发人员,你可以用axios发出post请求:

axios.post('http://localhost:12345', { firstName: 'Fred' })

或者制作自己的xhr,或者在HTML文件中制作表单并将其提交给服务器,例如:

<form action="http://localhost:12345" method="post">

或者使用curl或wget等进行请求。然后检查你的终端,一个原始的HTTP_MESSAGE应该出现在你的终端上,你可以开始你的快乐黑客;)

其他回答

Webhook Tester是一个很好的工具:https://webhook.site (GitHub)

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

你可以在本地运行Ken Reitz的httpbin服务器(在docker下或裸机上):

https://github.com/postmanlabs/httpbin

运行dockerized

docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin

直接在您的机器上运行

## install dependencies
pip3 install gunicorn decorator httpbin werkzeug Flask flasgger brotlipy gevent meinheld six pyyaml

## start the server
gunicorn -b 0.0.0.0:8000 httpbin:app -k gevent

现在,您在http://0.0.0.0:8000上运行了个人httpbin实例(对您的所有局域网可见)

Minimal Flask REST服务器

我想要一个返回预定义响应的服务器,所以我发现在这种情况下,使用一个最小的Flask应用程序更简单:

#!/usr/bin/env python3

# Install dependencies:
#   pip3 install flask

import json

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def root():
    # spit back whatever was posted + the full env 
    return jsonify(
        {
            'request.json': request.json,
            'request.values': request.values,
            'env': json.loads(json.dumps(request.__dict__, sort_keys=True, default=str))
        }
    )

@app.route('/post', methods=['GET', 'POST'])
def post():
    if not request.json:
        return 'No JSON payload! Expecting POST!'
    # return the literal POST-ed payload
    return jsonify(
        {
            'payload': request.json,
        }
    )

@app.route('/users/<gid>', methods=['GET', 'POST'])
def users(gid):
    # return a JSON list of users in a group
    return jsonify([{'user_id': i,'group_id': gid } for i in range(42)])

@app.route('/healthcheck', methods=['GET'])
def healthcheck():
    # return some JSON
    return jsonify({'key': 'healthcheck', 'status': 200})

if __name__ == "__main__":
    with app.test_request_context():
        app.debug = True
    app.run(debug=True, host='0.0.0.0', port=8000)

我已经创建了一个开源的可破解的本地测试服务器,您可以在几分钟内运行。你可以创建新的API,定义你自己的响应,并以任何你想要的方式破解它。

Github链接:https://github.com/prabodhprakash/localTestingServer

https://httpbin.org/

它将在请求中使用以下类型的任何数据进行回显:

https://httpbin.org/anything Returns most of the below. https://httpbin.org/ip Returns Origin IP. https://httpbin.org/user-agent Returns user-agent. https://httpbin.org/headers Returns header dict. https://httpbin.org/get Returns GET data. https://httpbin.org/post Returns POST data. https://httpbin.org/put Returns PUT data. https://httpbin.org/delete Returns DELETE data https://httpbin.org/gzip Returns gzip-encoded data. https://httpbin.org/status/:code Returns given HTTP Status code. https://httpbin.org/response-headers?key=val Returns given response headers. https://httpbin.org/redirect/:n 302 Redirects n times. https://httpbin.org/relative-redirect/:n 302 Relative redirects n times. https://httpbin.org/cookies Returns cookie data. https://httpbin.org/cookies/set/:name/:value Sets a simple cookie. https://httpbin.org/basic-auth/:user/:passwd Challenges HTTPBasic Auth. https://httpbin.org/hidden-basic-auth/:user/:passwd 404'd BasicAuth. https://httpbin.org/digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth. https://httpbin.org/stream/:n Streams n–100 lines. https://httpbin.org/delay/:n Delays responding for n–10 seconds.

一些在线httpbin:

https://httpbin.org/ https://httpbingo.org/ https://quic.aiortc.org/httpbin/

获取客户端ip,端口,ua..

http://ifconfig.io/

获取客户端ip, isp

https://www.cip.cc/