2017-08-04 82 views
1

要測試的東西,我想運行一個簡單的Web服務器:服務器實用程序:接受HTTPS POST請求,貓數據

  • 將監聽HTTPS POST請求
  • 打印接收到STDOUT POST數據(以及其他的東西,可能,所以它是好的,如果它只是貓的整個HTTP請求)

有沒有一種快速的方法來設置這樣的事情?我嘗試過使用OpenSSL的s_server,但它似乎只想響應GET請求。

回答

1

由於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