curl测试websocket接口连接性

有时候我们需要在linux环境下测试websocket接口连同性,包括nginx反向代理配置是否真确,websocket服务端是否正常等。这个时候我们可以通过以下命令测试。

curl --no-buffer -H 'Connection: keep-alive, Upgrade' -H 'Upgrade: websocket' -v -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: websocket' http://你的websocket接口地址 ws | od -t c
# curl --no-buffer -H 'Connection: keep-alive, Upgrade' -H 'Upgrade: websocket' -v -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: websocket' http://localhost:12345/ws ws | od -t c
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to localhost port 12345 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 12345 (#0)
> GET /ws HTTP/1.1
> User-Agent: curl/7.29.0
> Ho

猜你喜欢

转载自blog.csdn.net/cljdsc/article/details/128056510