首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >意外的HTTP请求: POST /mqtt/auth

意外的HTTP请求: POST /mqtt/auth
EN

Stack Overflow用户
提问于 2018-08-15 17:41:15
回答 1查看 288关注 0票数 1

我是emqtt的新手。我正在尝试使用emq_auth_http,但它不起作用。

我有这3个请求来控制一些数据,并发送回状态为200的数据。

代码语言:javascript
复制
app.post('/mqtt/auth', function(req, res) {
console.log('This is body ', req.body);
res.status(200).send(req.body);
});
app.post('/mqtt/superuser', function(req, res) {
console.log('This is body in superuser ', req.body);
res.status(200).send(req.body);
});
app.get('/mqtt/acl', function(req, res) {
console.log('This is params in acl ', req.params);
res.status(200).send(req.body);
});

请求在邮递员上运行良好。

我已经用docker在windows上配置了我的emqtt。我将我的配置文件放在/etc/plugins/emq_auth_http.conf中。

这是我的配置文件

代码语言:javascript
复制
## Variables: %u = username, %c = clientid, %a = ipaddress, %P = password, %t = topic

auth.http.auth_req = http://127.0.0.1:3000/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P

auth.http.super_req = http://127.0.0.1:3000/mqtt/superuser
auth.http.super_req.method = post
auth.http.super_req.params = clientid=%c,username=%u

## 'access' parameter: sub = 1, pub = 2
auth.http.acl_req = http://127.0.0.1:3000/mqtt/acl
auth.http.acl_req.method = get
auth.http.acl_req.params = 
access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t

然后我从仪表板启用了emq_auth_http

现在,当我尝试将mqtt客户机连接到服务器时,它没有调用api。It日志

代码语言:javascript
复制
09:28:29.642 [error] Unexpected HTTP Request: POST /mqtt/auth
09:28:29.644 [error] Client(19645050-9d1b-4c50-acf9- 
c1fe7e69eea8@172.17.0.1:60968): Username 'username' login failed for 404

有什么我漏掉的吗?为什么它不工作?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-02-20 15:39:07

容器中的127.0.0.1指的是容器本身,而不是主机。您应该设置主机ip,您可以通过发出命令/sbin/ip route|awk '/default/ { print $3 }'从容器中获取主机ip,该命令可以在here中找到

ps:这样你可以得到docker机器的ip,而不是主机的ip,如果你的服务是windows服务的,你可以从容器中到达主机的ip,即10.0.75.1。您可以在How to connect to docker host from container on Windows 10 (Docker for Windows)中找到它

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51856371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档