HTTPS get requests with NodeMCU and ESP8266

2019-07-31 13:39发布

I'm having problems doing a HTTPS GET request with NodeMCU, even though it seems it should be possible according to their documentations and this answer here on StackOverflow.

The code I'm trying is:

function getHTTPS()
    http.get('https://httpbin.org/get', nil, function(code, data)
        print(code, data)
    end)
end

enduser_setup.start(
  function()
    print("Connected to wifi as: " .. wifi.sta.getip())
    getHTTPS()
  end,
  function(err, str)
    print("enduser_setup: Err #" .. err .. ": " .. str)
  end
);

This gets me the result: -1 nil. If I change the URL from https://httpbin.org/get to http://httpbin.org/get, I get the expected result 200 <RESPONSE>.

My NodeMCU build is:

NodeMCU custom build by frightanic.com
    branch: master
    commit: 95e85c74e7310a595aa6bd57dbbc69ec3516e9c6 
    SSL: true
    modules: cjson,enduser_setup,file,gpio,http,mdns,net,node,tmr,uart,wifi  build
built on: 2016-08-27 07:36
powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)

What am I doing wrong?

1条回答
叼着烟拽天下
2楼-- · 2019-07-31 13:58

You're not doing anything wrong. If you did this with a firmware that's got DEBUG enabled you'd see that the SSL handshake fails.

The SSL library shipped with the Espressif SDK supports only 4 cipher suites. Neither of them are in the list of ciphers the SSL certificate used by httpbin.org supports.

查看更多
登录 后发表回答