lua中的http与https请求
2016-12-03 16:09
337 查看
OpenResty默认没有提供Http客户端,需要使用第三方提供;
此链接下载需要的资源:https://github.com/pintsized/lua-resty-http
http.lua http_headers.lua
这两个文件拷贝到openresty安装的lua的lib库。
http
https
此链接下载需要的资源:https://github.com/pintsized/lua-resty-http
http.lua http_headers.lua
这两个文件拷贝到openresty安装的lua的lib库。
local zhttp = require("resty.http")
http
function http_post_client(url, body, timeout) local httpc = zhttp.new() timeout = timeout or 30000 httpc:set_timeout(timeout) local res, err_ = httpc:request_uri(url, { method = "POST", body = body, headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then return nil, err_ else if res.status == 200 then return res.body, err_ else return nil, err_ end end end
https
function https_post_client(url, body, timeout, ssl_verify) local httpc = zhttp.new() timeout = timeout or 30000 httpc:set_timeout(timeout) --ssl_verify --传参表示:用于客户端时要求服务器必须提供证书,用于服务器时服务器会发出证书请求消息要求客户端提供证书 --不传参(false)表示:表示不验证 local res, err_ = httpc:request_uri(url, { ssl_verify = ssl_verify or false, method = "POST", body = body, headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then return nil, err_ else if res.status == 200 then return res.body, err_ else return nil, err_ end end end
相关文章推荐
- 十分钟学会Charles抓包(iOS的http/https请求)
- HttpClient请求https认证问题
- tomcat设置http请求自动跳转为https
- Swift - 使用SwiftHTTP通过HTTPS进行网络请求,及证书的使用
- Charles抓包(iOS的http/https请求)
- Nginx跳转任意Http请求到Https
- 如果现在是进行了 http 访问,则应该让请求跳转到 https 的 443 端口上的程序处理类
- 解决Nginx+Tomcat中https转http请求问题
- 十分钟学会Charles抓包(iOS的http/https请求)
- http 使用curl发起https请求
- nginx配置将http请求转发支持ssl双向认证https请求的正向代理
- 十分钟学会Charles抓包(iOS的http/https请求)
- 使用Python请求http/https时设置失败重试次数
- HttpClient 之 4.x.x版本以上的发送Https请求
- http 和 https 的请求区别
- HttpClient 发送 HTTP、HTTPS 请求的简单封装
- 用httpclient发送https协议请求以及javax.net.ssl.SSLHandshakeException解决办法
- tomcat 转发http请求到https
- JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
- 在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求