Get the App
SLTechnology News&Howtos  ›  Servers  › 

An alternative to reporting an error in the https request of lua in openresty

Shulou Source: shulou.com Published: 2022-06-03 09:58:50 09月21日 Update

There is a set of methods for requesting http/https in openresty: resty.http. The certificate file crt needs to be added for the https request, but I have been trying for a long time. All the certificate files under centos have been tried, and the certificate corresponding to the pin api.dingtalk.com cannot be found. It also reported a missing ssl module.

The normal result can be obtained by using curl request, so there is a bad idea.

Url = "https://oapi.dingtalk.com/gettoken?appkey="..appkey.."&appsecret="..appsecret

Cmd = "echo curl-s\" .url.. "\"

T = io.popen (cmd)

, d = string.find (t:read (),'{"errcode": 0, "access_token": "(% S+)", "errmsg')

Haha, doesn't it look weird? Lua invokes the command line, then captures the return information, and parses it with rules.

There is really no way, the certificate of this problem has been stuck for a long time, so now has not been solved, so using this method, but also perfectly avoid some of the lack of dependency in resty.

★ note that curl cannot be called directly here, because the returned value throws some process information and gets a pile of unparsed garbled code, which must be masked with echo before it can be regularized.

Tags: Certificate information method file regular problem weird garbled command idea method module result missing process seeking truth Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Docker Redmi Apple