使用 ngrok 在 Web 服务上托管的 Alexa 技能:这种主机和端口的组合需要 TLS

Alexa skill hosted on Web Service using ngrok : This combination of host and port requires TLS

我正在尝试在我的网络服务上托管 alexa 技能。

出于测试目的,我使用 ngrok 生成 https 网络服务 url。 我已将 URL 添加到 alexa 配置中。

当我尝试测试该服务时,我可以看到我的本地 ngrok 服务器正在接收如下请求。

GET /alexa/service/processrequest
Summary
Headers
Raw
Binary
GET /alexa/service/processrequest HTTP/1.1
Host: 9286ef9a.ngrok.io
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
X-Forwarded-Proto: https
X-Forwarded-For: 49.248.168.79

但是,它没有到达我正在通过 eclipse 远程断点调试的 webservice/skill 代码。 在 ngrok 中,我可以看到以下错误:

HTTP/1.1 400 
Content-Type: text/plain;charset=ISO-8859-1
Connection: close

Bad Request
This combination of host and port requires TLS.

我已通过生成自签名证书在 https 端口 443 上将 spring-boot 配置为 运行。相同的证书上传到 alexa 开发者控制台。

如果我使用 ngrok url 在 google chrome 中访问我的网络服务 url,它会给出相同的错误:

但是如果我在 url 中使用 localhost,那么 chrome 能够检测到 https,如下所示:

我无法找到根本原因。 这里有人可以帮我吗?

我已经找到问题的答案并将其发布,以便它可以帮助其他人了解在上述情况下该怎么做。

Spring-boot 正在端口 443 上为我的网络服务创建 https 端点。 在 chrome 中,如果我使用 https url 访问此端口,它可以正常工作,但如果我使用 http[=41= 访问此端口] url,错误如上图所示。 因此,总的来说,spring-boot 表示请求正在到达 http endpoint,而它本应在https 端点。

罪魁祸首是 NGROK。 :-(

尽管 ngrok 正在为 public 访问创建 https 端点,但它并未创建从 ngrok 客户端(运行ning 在我的电脑上)到 tomcat 服务器的 https 隧道。 使用 -tls 选项,ngrok 支持https/tls 隧道,但这种情况仅在 ngrok.

的付费计划中发生

和ngrok类似,我也探索过localtunnel,但它也有同样的问题tls隧道

解决方法

因为我做所有这些都是为了在我的本地机器上调试技能开发,所以我尝试了第 2 点提到的其他证书提供选项 here。 此选项允许我将本地 Web 服务器用作仅 http,现在 ngrok 或 localtunnel 可以很好地支持它。 :-)

因此,按照我在开发期间启用调试 Alexa Skill 所采取的步骤:

  1. 在 Alexa Web 控制台中使用 SSL 配置的第二个选项。
  2. 删除了本地 SSL 端点和 运行 tomcat 纯 http 而不是 https。
  3. 在 Alexa 网络控制台中使用了 ngrok https 端点。

我们可以在 ngrok 上注册并设置 authtoken(https://dashboard.ngrok.com/get-started/your-authtoken 上的步骤)

然后使用ngrok http https://localhost:8081,然后ngrok转发到https