我需要一个实时测试服务器,它通过HTTP GET接受我对基本信息的请求,并允许我POST(即使它真的什么都不做)。这完全是为了测试目的。
这里有一个很好的例子。它很容易接受GET请求,但我需要一个接受POST请求以及。
有人知道我也可以发送虚拟测试消息的服务器吗?
我需要一个实时测试服务器,它通过HTTP GET接受我对基本信息的请求,并允许我POST(即使它真的什么都不做)。这完全是为了测试目的。
这里有一个很好的例子。它很容易接受GET请求,但我需要一个接受POST请求以及。
有人知道我也可以发送虚拟测试消息的服务器吗?
当前回答
看看PutsReq,它与其他类似,但它也允许您使用JavaScript编写您想要的响应。
其他回答
你可以在本地运行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)
https://www.mockable.io。它有很好的功能,无需登录就可以获得端点(24小时临时帐户)
如果你想要一个本地测试服务器接受任何URL并将请求转储到控制台,你可以使用node:
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]
Nc一行本地测试服务器
在Linux下用一行设置本地测试服务器:
nc -kdl localhost 8000
另一个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
netcat-openbsd包中的nc是广泛可用的,并且已预先安装在Ubuntu上。
在Ubuntu 18.04上测试。
下面是一个邮差回声: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":{"...