服务器实用程序:接收 HTTPS POST 请求,cat 数据

Server utility: receive HTTPS POST requests, cat the data

为了测试一些东西,我想 运行 一个简单的网络服务器:

有没有快速设置这样的方法?我试过使用 OpenSSL 的 s_server,但它似乎只想响应 GET 请求。

由于s_server不支持POST请求,你应该使用socat而不是openssl s_server:

# socat -v OPENSSL-LISTEN:443,cert=mycert.pem,key=key.pem,verify=0,fork 'SYSTEM:/bin/echo HTTP/1.1 200 OK;/bin/echo;/bin/echo this-is-the-content-of-the-http-answer'

基本参数如下:

  • fork: 循环多次请求

  • -v:将 POST 数据(和其他内容)显示到 STDOUT

  • verify=0: 不要求相互认证

现在,举个例子:

我们使用以下 POST 请求:

% wget -O - --post-data=abcdef --no-check-certificate https://localhost/
[...]
this-is-the-content-of-the-http-answer

我们看到以下 socat 输出:

# socat -v OPENSSL-LISTEN:443,cert=mycert.crt,key=key.pem,verify=0,fork 'SYSTEM:/bin/echo HTTP/1.1 200 OK;/bin/echo;/bin/echo this-is-the-content-of-the-http-answer'
> 2017/08/05 03:13:04.346890  length=212 from=0 to=211
POST / HTTP/1.1\r
User-Agent: Wget/1.19.1 (freebsd10.3)\r
Accept: */*\r
Accept-Encoding: identity\r
Host: localhost:443\r
Connection: Keep-Alive\r
Content-Type: application/x-www-form-urlencoded\r
Content-Length: 6\r
\r
< 2017/08/05 03:13:04.350299  length=16 from=0 to=15
HTTP/1.1 200 OK
> 2017/08/05 03:13:04.350516  length=6 from=212 to=217
abcdef< 2017/08/05 03:13:04.351549  length=1 from=16 to=16

< 2017/08/05 03:13:04.353019  length=39 from=17 to=55
this-is-the-content-of-the-http-answer