Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad Request: The plain HTTP request was sent to HTTPS port #171

Closed
lonag opened this issue Jun 11, 2024 · 3 comments
Closed

400 Bad Request: The plain HTTP request was sent to HTTPS port #171

lonag opened this issue Jun 11, 2024 · 3 comments

Comments

@lonag
Copy link

lonag commented Jun 11, 2024

使用httpc.get访问https接口,看表现是会用http访问。

@sniper00
Copy link
Owner

sniper00 commented Jun 11, 2024

Moon不直接支持https, HTTPS需要用代理,可以看下wiki

https://github.com/sniper00/moon/wiki/Http#httpclient-http%E8%BD%AChttps%E6%AD%A3%E5%90%91%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE

示例

--httpsGoogle登录令牌认证
local function GoogleTokenVerify(token, userId)
    
    local url = string.format("https://oauth2.googleapis.com")
    local response = httpc.get(url, {
        path = string.format("/tokeninfo?id_token=%s", token),
        proxy = "http://127.0.0.1:8443"  -- 这里设置nginx http->https 正向代理
    })
    if response == nil or response.status_code ~= 200 or response.content == nil then 
        return 1
    end

    local jsonStr = json.decode(response.content)
    if jsonStr == nil then 
        return 2
    end

    if jsonStr["sub"] == nil or jsonStr["sub"] ~= userId then 
        return 3
    end

    return 0
end

@lonag
Copy link
Author

lonag commented Jun 11, 2024

好吧

@sniper00
Copy link
Owner

好吧

主要原因是带上 OpenSSL 编译,会增加编译复杂度,使用nginx更加简洁高效, 并且线上环境一般都会依赖nginx。开发环境一般在内网部署一个,可以项目组共用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants