问题
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).
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\r\n"..
"Host: google.com\r\n"..
"Accept: */*\r\n"..
"User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
"\r\n\r\n")
end )
conn:on("disconnection", function(conn) print("disconnected") end )
conn:connect(443,"google.com")
Nothing is triggered (not even the "connected").
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
Could someone tell me what I am doing wrong? Someone reported the problem on Reddit, but no final solution given.
回答1:
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.
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://stackoverflow.com/questions/35988328/https-ssl-get-request-with-nodemcu