-
-
Save htp/fbce19069187ec1cc486b594104f01d0 to your computer and use it in GitHub Desktop.
curl --include \ | |
--no-buffer \ | |
--header "Connection: Upgrade" \ | |
--header "Upgrade: websocket" \ | |
--header "Host: example.com:80" \ | |
--header "Origin: http://example.com:80" \ | |
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \ | |
--header "Sec-WebSocket-Version: 13" \ | |
http://example.com:80/ |
I recommend adding --http1.1
to your curl command. The Connection and Upgrade headers are not valid in http/2 and curl will use http/2 if your server supports it.
I lost a few hours trying to figure out why these headers were disappearing when debugging my httpd web socket rewrite rules for the first time.
Once curl opens up the connection to the websocket, how to send other commands
I recommend adding
--http1.1
to your curl command. The Connection and Upgrade headers are not valid in http/2 and curl will use http/2 if your server supports it.I lost a few hours trying to figure out why these headers were disappearing when debugging my httpd web socket rewrite rules for the first time.
^^ this. and also -o -
after the curl command so you dont get the binary output warning.
curl -o - --http1.1 --include \
For those who failed the request with Sec-WebSocket-Key, RFC 6455 does require the key to be 16 bytes and the resulting base64 encoded string must be 24 bytes long as @moolitayer quoted. The example from Wikipedia "x3JJHMbDL1EzLkh9GBhXDw==" does a great job. Or simply add some padding to the gist SGVsbG8sIHdvcmxkIQAAAA== also works.
with recent browsers like firefox92, copy as curl in network will add the required settings, you only have to change wss:// to http://
did anybody try same command using TLS? to "wss://echo.websocket.org"
Replacing "http://" with "https://" in the curl command seems to do the trick.
Curious whether anyone has gotten a clean termination after the first message, along the lines of websocat --one-message ...
. I tried using --max-time
, but the curl return status ends up being nonzero.
I recommend adding
--http1.1
to your curl command. The Connection and Upgrade headers are not valid in http/2 and curl will use http/2 if your server supports it.I lost a few hours trying to figure out why these headers were disappearing when debugging my httpd web socket rewrite rules for the first time.
Thanks, it works!
curl --include \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Sec-WebSocket-Key: qwerty" \
http://localhost:8000/
This worked for me. I didn't need all the header items
Anyone know if you can use this to send data (i.e. from stdin or a file) through the web socket? I tried -T -
, but that doesn't seem to work.
curl --include \
-H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Sec-WebSocket-Key: qwerty" \
-H "Sec-WebSocket-Version: 13" \
https://example.com -k
Just for my convenience: