HTTPS (SSL) 使用 NodeMCU 获取请求 [英] HTTPS (SSL) get request with NodeMCU

查看:28
本文介绍了HTTPS (SSL) 使用 NodeMCU 获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用运行 NodeMCU 的 ESP8266 向 googleapi.com 执行 GET 请求,以从谷歌日历 API 获取一些数据.该网站只允许安全连接 (HTTPS/SSL).

I would like to perform GET requests to googleapi.com with my ESP8266 running NodeMCU, to get some data from the google Calendar API. The website allows only secured connection (HTTPS/SSL).

首先,我一直在尝试连接到 google.com(安全)以尝试一下,但也没有成功.这是 LUA 代码:

First, I've been trying to connect to google.com (secured) to give it a try, but with no success either. Here is the LUA code:

conn=net.createConnection(net.TCP, 1)
conn:on("receive", function(sck, c) print(c) end )
conn:on("connection", function(conn)
      print("connected")
      conn:send("HEAD / HTTP/1.1
".. 
             "Host: google.com
"..
             "Accept: */*
"..
             "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
             "

") 
end )
conn:on("disconnection", function(conn)  print("disconnected") end )
conn:connect(443,"google.com")

没有任何东西被触发(甚至连连接"都没有).

Nothing is triggered (not even the "connected").

我还从网站 http://下载了 最新 版本的 nodemcu(主分支)nodemcu-build.com 通过选择 SSL 支持.

I also downloaded the latest version of nodemcu (master branch) from the website http://nodemcu-build.com by selecting the SSL support.

NodeMCU custom build by frightanic.com
    branch: master
    commit: c8037568571edb5c568c2f8231e4f8ce0683b883
    SSL: true

谁能告诉我我做错了什么?有人在 Reddit 上报告了这个问题,但没有给出最终解决方案.

Could someone tell me what I am doing wrong? Someone reported the problem on Reddit, but no final solution given.

推荐答案

net 模块所需的修复程序尚未在 master 分支上可用.PR 1014 仅在 2 月初才合并到 dev 分支.

The required fix for the net module is not yet available on the master branch. PR 1014 was only merged to the dev branch in early February.

dev 分支有一个 HTTP 客户端模块,通过它可以将您的代码缩短为单行代码.请参阅 http://nodemcu.readthedocs.org/en/dev/en/modules/http/#httpget 了解详情.

The dev branch has an HTTP client module with which your code can be shortened to a one-liner. See http://nodemcu.readthedocs.org/en/dev/en/modules/http/#httpget for details.

这篇关于HTTPS (SSL) 使用 NodeMCU 获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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