javascript - Error wss://mqtt.eclipse.org when create mqtt client
问题描述
I am in my first mqtt project and my project is ok in local. But when I deployed it to heroku, It failed. This is the error:
Mixed Content: The page at 'https://showbd.herokuapp.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://mqtt.eclipse.org/mqtt'. This request has been blocked; this endpoint must be available over WSS. k._doConnect @ mqttws31.min.js:36 k.connect @ mqttws31.min.js:31 I.connect @ mqttws31.min.js:65 (anonymous) @ app.js:10
I declared client in app.js file.
var MQTT_CLIENT = new Paho.MQTT.Client("mqtt.eclipse.org", Number(80), "/mqtt", MQTT_CLIENT_ID);
Thanks for help!
解决方案
您部署的网页已通过 HTTPS 安全加载,为防止不安全的内容混入其中,它将阻止与非 TLS 保护位置的任何连接。在这种情况下,您尝试mqtt.eclipse.org
在端口 80 上建立不安全的连接。
解决方案是告诉 Paho 客户端连接到端口 443 上的 Secure Websocket 端点。您可以通过将完整 URL 传递给 Paho 客户端构造函数来完成此操作
var MQTT_CLIENT = new Paho.MQTT.Client("wss://mqtt.eclipse.org", MQTT_CLIENT_ID);
推荐阅读
- android - 构建设备树以在 Rockchip rk3288 板上运行 Linux 内核
- batch-file - 在另一个文件 .bat 中删除具有其名称和路径的文件
- javascript - 将整个网页放入 document.write();
- c# - C#将数字插入到排序位置的列表框中
- python - Django 模型不适用于 Oracle 数据库
- cloud-foundry - 禁用 Cloud Foundry RTR 日志
- regex - 删除文件中与模式不匹配的行
- excel - 隐藏多列 VBA Excel
- makefile - Makefile 目标作为两个列表的叉积
- java - 如何知道 Eclipse 插件项目中的透视图是否发生了变化?