vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
6.74k stars 261 forks source link

how to send POST request #59

Open jschwinger233 opened 4 years ago

jschwinger233 commented 4 years ago

I want to send request as followed:

POST /v1.40/exec/fd1cfa1baccabe2cc990db8a89b77c172d2625d2ac10f0d484499cd19c90e084/start HTTP/1.1
Host: localhost:2375
User-Agent: Docker-Client/19.03.2 (darwin)
Content-Length: 28
Connection: Upgrade
Content-Type: application/json
Upgrade: tcp

{"Detach":false,"Tty":true}

but I failed to find the arguments to specify request method as well as post body...

jschwinger233 commented 4 years ago

oh never mind, I figured it out using telnet...

$ telnet localhost 2375
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
POST /v1.40/exec/cbaba521569293af53a3814af10a19272b0e7be0087129df7fc3bcd6d5ddd319/start HTTP/1.1
Host: localhost:2375
User-Agent: Docker-Client/19.03.2 (darwin)
Content-Length: 28
Connection: Upgrade
Content-Type: application/json
Upgrade: tcp

{"Detach":false,"Tty":true}
HTTP/1.1 101 UPGRADED
Content-Type: application/vnd.docker.raw-stream
Connection: Upgrade
Upgrade: tcp
Api-Version: 1.40
Docker-Experimental: true
Ostype: linux
Server: Docker/19.03.2 (linux)

bash-5.0#

but it can be really helpful if websocat can achieve this conveniently, thanks~

vi commented 4 years ago

May happen with Websocat 2.0. Here is some bit of preview:

$ ./target/debug/websocat -v -b - http-request:tcp:127.0.0.1:1234 -X POST --request-uri /v1.40/exec/fd1cfa1baccabe2cc990db8a89b77c172d2625d2ac10f0d484499cd19c90e084/start --request-header 'Contention: upgrade' --request-header 'Upgrade: tcp' --request-header 'Content-Length: 0' --request-header 'Content-Type: application/json'
[INFO  websocat::net_peer] Resolving hostname to IP addresses
[INFO  websocat::net_peer] Got IP: 127.0.0.1:1234
[INFO  websocat::net_peer] Connected to TCP 127.0.0.1:1234
[INFO  websocat::http_peer] Issuing HTTP request
[INFO  websocat::http_peer] HTTP response status: 200 OK
12345
qwerty
67890
1234
zxcvb
asdfg
[INFO  websocat::sessionserve] Forward finished
[INFO  websocat::sessionserve] Reverse finished
[INFO  websocat::sessionserve] Both directions finished
$ nc -lp 1234
POST /v1.40/exec/fd1cfa1baccabe2cc990db8a89b77c172d2625d2ac10f0d484499cd19c90e084/start HTTP/1.1
contention: upgrade
upgrade: tcp
content-length: 0
content-type: application/json

HTTP/1.1 200 OK^M
^M
qwerty
12345
67890
1234
zxcvb
asdfg

HTTP body cannot be specified yet, an option needs to be added for this.

vi commented 4 years ago

Do you want an early pre-built pre-alpha version of Websocat with this feature? Option names may be changed before the release. If yes, specify platform.

jschwinger233 commented 4 years ago

oh oh much appreciate but I had completed my task, I can just wait for stable one..

thank you very much all the same!