我需要一个实时测试服务器,可以通过HTTP GET接受我的基本信息请求,并允许我进行POST(即使它实际上没有做任何事情)。这完全是为了测试目的。
一个很好的例子在这里。它轻松地接受GET请求,但我需要一个可以接受POST请求的服务器。
是否有人知道我可以发送虚拟测试消息的服务器?
它回显了您的请求中使用的数据,这些类型包括:
$ pip install httpbin gunicorn && gunicorn httpbin:app
,它是用于安装和运行 httpbin.org 的。 - HVNSweetingcurl -iX POST httpbin.org/post
,它将返回200。 - Robert这里有ptsv3.com
"在这里,您将找到一个服务器,它可以接收您想要提供的任何POST,并为您存储内容以供查看。"
Webhook Tester是一款非常好用的工具:https://webhook.site(GitHub)
对我来说,它展示了请求者的IP地址,这在你需要列入白名单的IP地址并不确定IP是什么时非常有帮助。
nc
一行命令的本地测试服务器
在Linux下只需一行命令即可设置本地测试服务器:
nc -kdl 8000
wget
这样等待回复的HTTP客户端的阻塞,实际上发送一个最小的空HTTP回复,这样您可以在另一个shell上进行更多的测试,而无需手动中断客户端(感谢nikniknik和zelanix在评论中提供的建议)。while true; do printf 'HTTP/1.1 200 OK\r\n\r\n' | nc -Nl 8000; done
wget http://localhost:8000
GET / HTTP/1.1
User-Agent: Wget/1.19.4 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: localhost:8000
Connection: Keep-Alive
nc
来自netcat-openbsd
软件包,在Ubuntu上广泛可用且预装。
有关最小值HTTP回复的相关问题:
在Ubuntu 22.10上测试,nc
来自netcat-openbsd 1.218。
while true; do echo -e "HTTP/1.1 200 OK\n" | nc -Nl 8000; done
时,nc都会回复一个200 OK的代码。 - nikniknik如果你想要一个本地测试服务器,它可以接受任何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]
http://requestb.in 类似于其他提到的工具,并且还有一个非常好的用户界面。
RequestBin 提供一个URL,它会收集发送到它的请求,并让您以人性化方式检查它们。 使用 RequestBin 查看您的 HTTP 客户端正在发送的内容,或者检查和调试 webhook 请求。
尽管自2018年3月21日起已停止服务。
由于持续滥用导致很难可靠地保持该网站运行,我们已经停止了 RequestBin 的公共托管版本。请参见说明以设置自己的本地实例。
看看PutsReq,它与其他类似的工具相似,但它还允许您使用JavaScript编写所需的响应。
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":{"...
httpbin
服务器(使用Docker或裸机):
https://github.com/postmanlabs/httpbin
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
我想要一个返回预定义响应的服务器,所以在这种情况下我发现使用最小的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)
alias httpbin='docker run -p 80:80 kennethreitz/httpbin'
- Sean Breckenridgehttp://localhost:12345
,例如,如果你是一个 JavaScript 开发者,你可以使用 axios 发送一个 POST 请求。axios.post('http://localhost:12345', { firstName: 'Fred' })
<form action="http://localhost:12345" method="post">
curl
、wget
或其他方法发送请求。然后检查您的终端,一个原始的HTTP_MESSAGE应该出现在您的终端上,您可以开始愉快地进行黑客攻击 ;)
nc -l 12345
。 - Silvio Biasiol