http - 服务器实用程序 : receive HTTPS POST requests, cat 数据

标签 http https openssl netcat

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

  • 将监听 HTTPS POST 请求
  • 将接收到的 POST 数据打印到 STDOUT(可能连同其他内容,所以如果它只捕获整个 HTTP 请求就没问题)

有没有快速的方法来设置这样的东西?我试过使用 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

关于http - 服务器实用程序 : receive HTTPS POST requests, cat 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45515693/

相关文章:

apache - 在 Ubuntu 12.04 上的 Apache 上配置 SVN 服务器

swift - 如何使用 Alamofire 上传图片并在参数中引用文件

ubuntu - svn: 'https://...' 的选项:无法连接到服务器

certificate - OpenSSL 使用自定义主题字段生成和签署证书

ssl - OpenSSL:字段名称缩写有问题吗?

python - Shopify 不会停止向 Flask 应用程序发送 webhook

Ruby HTTP 库与 Facebook 应用程序连接重置

c++ - 从客户端程序嗅探 HTTPS 流量

node.js - 发出 https 发布请求时,node.js 中的错误 "ssl3_get_record:wrong version number"

google-cloud-platform - Google 负载均衡器拒绝自签名证书