day*_*mer 7 javascript curl websocket
我看到有websocket端点可以通过Java测试来处理鳍.在日志我看到
Connecting to: ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets
Run Code Online (Sandbox Code Playgroud)
就像任何其他RESTAPI我想通过浏览器或卷曲来打它,但当我这样做,我看到
? tweetstream git:(master) ? curl ws://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets
curl: (1) Protocol ws not supported or disabled in libcurl
Run Code Online (Sandbox Code Playgroud)
和
? tweetstream git:(master) ? curl http://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets
<html><head><title>Error</title></head><body>Not Found</body></html>%
Run Code Online (Sandbox Code Playgroud)
有没有办法用浏览器/卷曲测试websocket API?
Dam*_*ian 10
这对我有用:
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" http://echo.websocket.org
Run Code Online (Sandbox Code Playgroud)
来自:http://www.thenerdary.net/post/24889968081/debugging-websockets-with-curl
为了完整起见,我想添加我自己的 CLI 工具:websocat。
$ websocat wss://echo.websocket.org/
qwer
qwer
1234
1234
Run Code Online (Sandbox Code Playgroud)
它不执行问题的“浏览器”部分,但在这种情况下应该是“curl”的有效替代品。
小智 7
如果你的意思是测试websockets的实现,我发现Autobahn的测试套件非常有用:http: //autobahn.ws/
如果您只想使用websocket进行面条化,我建议您使用chrome之类的浏览器中的开发人员工具来建立连接和发送/ recv数据:
var ws = new WebSocket("ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets");
ws.onclose = function() { // thing to do on close
};
ws.onerror = function() { // thing to do on error
};
ws.onmessage = function() { // thing to do on message
};
ws.onopen = function() { // thing to do on open
};
ws.send("Hello World");
Run Code Online (Sandbox Code Playgroud)
我必须使用此命令才能使其工作:
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" -H "Sec-WebSocket-Version: 13" -H 'Sec-WebSocket-Key: +onQ3ZxjWlkNa0na6ydhNg==' http://www.websocket.org
Run Code Online (Sandbox Code Playgroud)
我正在使用 Jetty,如果我没有添加 Sec-WebSocket-Version/Sec-WebSocket-Key 则不起作用。只是为了记录。
| 归档时间: |
|
| 查看次数: |
16074 次 |
| 最近记录: |