惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - RedFox(低调)

多大的船决定要承担多大的阻力,多大的风浪会炼出多厉害的船长,大副,二副,水手。。。。很多时候不是你选择了风浪,而是风浪选择并决定了你!优秀的水手觉得不是战胜了风浪,而是适应了风浪。 jdk国内镜像 基于vue-cli的vs code设置 maven 国内完整源 怎么看待MYSQL的性能 java dom4j 读写XML cas4.2的安装 java websocket 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别 为何Google这类巨头会认为敏捷开发原则是废话? git ldap 获取大众点评数据 svn for vs SQL 导出表数据存储过程 色彩设计,是产品设计,营销渠道的一个重要环节 sql xml 腾讯或正在陷入全面危机? 项目实施与管理的几点建议 ERP与进销存软件的区别
解决openresty http客户端不支持https的问题
RedFox(低调) · 2016-03-09 · via 博客园 - RedFox(低调)

 OpenResty默认没有提供Http客户端,需要使用第三方提供;当然我们可以通过ngx.location.capture 去方式实现,但它只能发送一个子请求。

第三方基本是以lua-resty-http为代表,这个类库如果去访问http和正规的https是没有问题,也挺好用的,但如果访问使用山寨证书的请求会出一些错误,比如:handshake failed,socket error等等之类的错误。对于种我的解决办法是使用curl,可以很好解决这个问题,现在来看算是比较完美的。
具体代码如下:

local curl = require("luacurl")

local function postJson(url,postData,c)
    local result = { }
    if c == nil then
        c = curl.new()
    end
    c:setopt(curl.OPT_URL, url)
    c:setopt(curl.OPT_SSL_VERIFYHOST,0)
    c:setopt(curl.OPT_SSL_VERIFYPEER,false)
    c:setopt(curl.OPT_POST,true)
    c:setopt(curl.OPT_HTTPHEADER, "Content-Type: application/json")
    c:setopt(curl.OPT_POSTFIELDS, postData)
    c:setopt(curl.OPT_WRITEDATA, result)
    c:setopt(curl.OPT_WRITEFUNCTION, function(tab, buffer)
        table.insert(tab, buffer)
        return #buffer
    end)
    local ok = c:perform()
    return ok, table.concat(result)
end

 local ok,html = postJson(serverUrl,data);
        if ok then
            ngx.say(html)
        end