本文介绍了Vert.x websocket 客户端 - 400 错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从我的 Java verticles 连接 Cex.IO websocket API?em>
问题是 Vert.x 没有为我提供只与 WsURI 连接的方法 就像 Node.JS 一样.我必须指定端口和主机并获得 HTTP 400 错误请求异常.
The problem is that Vert.x doesn't provide me with a way to connect only with WsURI as Node.JS does. I have to specify port and host and get HTTP 400 Bad Request exception.
使用 Node.js,您可以:
With Node.js you do:
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.connect("wss://ws.cex.io/ws/");
使用 Vert.x,您必须做到
With Vert.x you have to do
int host = 443; // That's defaults
String host = "cex.io"; // Am I right by specifying this host?
HttpClient client = Vertx.vertx().createHttpClient();
client.websocket(port, host, "wss://ws.cex.io/ws/", ws -> { ...});
推荐答案
这个 HttpClient#websocket 方法将相对 URI 作为第三个参数.
This HttpClient#websocket method takes a relative URI as third parameter.
您应该能够像这样连接:
You should be able to connect like this:
client = vertx.createHttpClient(new HttpClientOptions()
.setDefaultHost("ws.cex.io")
.setDefaultPort(443)
.setSsl(true));
client.websocket("/ws", ws -> {
// Work with the websocket
});
这篇关于Vert.x websocket 客户端 - 400 错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!