如何打开WebSocket端点? [英] How to hit the WebSocket Endpoint?

查看:1344
本文介绍了如何打开WebSocket端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有websocket端点,它与Java测试工作。在日志中看到

I see that there is websocket endpoint which works out fins with Java tests. In logs I see

Connecting to: ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets  

与任何其他 REST API我想通过浏览器或curl打它,但当我这样做,我看到

Just like any other REST API I would like to hit it via browser or curl, but when I do that I see

➜  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  

➜  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>%  

websocket APIs with browser / curl?

Is there a way to test websocket APIs with browser/curl?

推荐答案

如果你的意思是测试websockets的实现,我发现Autobahn的测试套件非常实用: http://autobahn.ws/

If you mean literally to test the implementation of websockets, I found Autobahn's test suite to be very useful: http://autobahn.ws/

如果你只是想用一个websocket面条,我建议使用浏览器中的开发工具,如chrome连接和发送/ recv数据:

If you just want to noodle with a websocket I would recommend using the developer tools in a browser like chrome to make a connection and send/recv data:

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");

这篇关于如何打开WebSocket端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆