lua http solicitud se envía, sin http.lua luajit predeterminado biblioteca, es necesario descargar y colocar el luajit el directorio correspondiente.
En primer lugar, descargar http.lua y http_headers.lua biblioteca
Referencia: HTTPS: //www.zixuephp.net/article-448.html
fiesta
location = / testscript {
texto default_type / plain;
content_by_lua_file html / luafile / test.lua;
}
golpetazo
test.lua vim
zhttp locales = El requieren "resty.http"
archivo de registro de errores 1. Ejecutar Ver nginx le pedirá ningún http.lua:
2. Descargar http.lua y http_headers.lua biblioteca
Página de descarga: https: //github.com/pintsized/lua-resty-http
Descarga Directa: http_headers.lua-http.lua.rar
Una vez que haya descargado en el directorio correspondiente, el directorio está aquí:
golpetazo
[root @ resty zixuephp] # pwd
/usr/local/LuaJIT/share/luajit-2.0.5/resty
git clone https://github.com/pintsized/lua-resty-http.git
nginx reinicio.
Dos, lua http código de petición transmitida
solicitud 1.get
golpetazo
= zhttp locales requieren "resty.http"
función local http_post_client (url, tiempo de espera)
local de httpc = zhttp.new ()
timeout = tiempo de espera o 30.000
httpc: set_timeout (timeout)
res locales, err_ = httpc: request_uri (url, {
method = "GET",
cabeceras = {
[ "Content-Type"] = "application / x-www-form-urlencoded",
}
})
httpc: set_keepalive (5000, 100)
--httpc: close ()
res de retorno, err_
final
2.post请求
golpetazo
= zhttp locales requieren "resty.http"
función local http_post_client (url, cuerpo, tiempo de espera)
local de httpc = zhttp.new ()
timeout = tiempo de espera o 30.000
httpc: set_timeout (timeout)
res locales, err_ = httpc: request_uri (url, {
method = "POST",
cuerpo = cuerpo,
cabeceras = {
[ "Content-Type"] = "application / x-www-form-urlencoded",
}
})
httpc: set_keepalive (5000, 100)
httpc: close ()
si entonces no RES
volver nula, err_
más si res.status == 200 y luego
volver res.body, err_
otra cosa
nula rentabilidad, err_ de
que
lo
golpetazo
--get
RESP locales, ERR = http_post_client ( "http://zixuephp.net/index.html?name=test", 3000)
--post
cuerpo local = { "name" = "Test"}
RESP locales, ERR = http_post_client ( "http://zixuephp.net/index.html?name=test", cuerpo,
3000) ----------------
responsabilidad: Este artículo es wangc_gogo CSDN bloggers' "el artículo original, siga el CC 4.0 del acuerdo de derechos de autor BY-SA, que se reproduce, por favor incluya el enlace de la fuente original y esta declaración.
fuente original: https: //blog.csdn.net/wangc_gogo/article/details/98318980