url请求
--[[local g = require 'library.global'
--__ml_ss = mlc.prefix.ml_psession..tostring(os.time());
local mlc = require 'ml_config'
local function haslogin()
local r = g.getredis()
local s,e = r:get();
if s ~= nil then
return true;
else
return false;
end
end
local ffiok, ffi = pcall(require,"ffi")
--require('library.kav_fnc')
--md5 = require('library.md5')
system_hid = {}
--require "redis"
--[[local myclient = redis.connect();
local all_keys = myclient:keys("*");
local all_values = myclient:mget(all_keys);
for i, k in ipairs( all_keys) do
local v = all_values[i];
print(k, v)
end --]]
--[[local result ={}
for i = 1,#(KEYS) do
result[i]= redis.call('get',KEYS[i])
end
return result--]]
--[[local result={};
local myperson=KEYS[1];
local nums=ARGV[1];
local myresult =redis.call("hkeys",myperson);
for i,v in ipairs(myresult) do
local hval= redis.call("hget",myperson,v);
redis.log(redis.LOG_WARNING,hval);
if(tonumber(hval)<tonumber(nums)) then
table.insert(result,1,v);
end
end
fodr i=1,#(result) do
print(result[i])
end
return result;--]]
--]]
--[[local myKeyList=redis.call("keys","string.tmd.*")
local count=0
local tempStrlocal str --experience all the keys 遍历数组 有多种方法遍历数组 网上很容易找到
for index,line in pairs(myKeyList) do --通过Redis API调用 获取line的值 line即为键
str=redis.call("get",line) --string.sub() match() gmatch() len() 对字符串操作的函数
local matchStr=string.match(str,"http://tmd2.ghost.com/comment/images/%d+.png")
--匹配到http链接 --下面注释掉的函数可以在"服务器"端打印变量的值
print(matchStr)
local reserveStr=matchStr.sub(matchStr,40,string.len(matchStr));
--将链接截断,并替换成指定的模式
--print(reserveStr) -- .. 用于连接字符串 不像java中用 + 此处替换 str为源 中间为模式 右边为目标
tempStr=string.gsub(str,"http://tmd2.ghost.com/comment/images/%d+.png","http://tmd2-img.ghost.com/1/"..reserveStr) --print(tempStr) --替换完后将之重新设置到Redis中
redis.call("set",line,tempStr)
print(redis.call("get",line))
end--]]
---------------------------------------------
二、lua发送http请求代码
1.get请求
bash
local zhttp = require "resty.http"
local function http_post_client(url, timeout)
local httpc = zhttp.new()
timeout = timeout or 30000
httpc:set_timeout(timeout)
local res, err_ = httpc:request_uri(url, {
method = "GET",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
}
})
httpc:set_keepalive(5000, 100)
--httpc:close()
return res, err_
end
2.post请求
bash
local zhttp = require "resty.http"
local 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",
}
})
httpc:set_keepalive(5000, 100)
httpc:close()
if not res then
return nil, err_
else if res.status == 200 then
return res.body, err_
else
return nil, err_ end
end
end
bash
--get
local resp, err = http_post_client("http://zixuephp.net/index.html?name=test",3000)
--post
local body = {"name" = "test"}
local resp, err = http_post_client("http://zixuephp.net/index.html?name=test",body,3000)
----------------------------------------
require("curl")
local ipList =
{
"192.168.1.1",
"192.168.1.1",
}
--登陆
function loginWeb(ip)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/")
c:setopt(curl.OPT_POSTFIELDS, "Username=admin&Password=admin&Frm_Logintoken=&action=login")
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
return #buffer
end)
c:perform()
end
--访问页面
function accessPage(ip)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/xxpage.html")
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
return #buffer
end)
c:perform()
end
--设置参数
function setParameter(ip, file)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/xx.php")
c:setopt(curl.OPT_POSTFIELDS, "DaylightSavingsUsed=1&Dscp=-1")
local htmlTable = {}
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
table.insert(htmlTable, buffer)
return #buffer
end)
c:perform()
local htmlStr = table.concat(htmlTable);
local resultBuff = "";
if string.match(htmlStr, "<result>SUCC</result>") ~= nil then
resultBuff = ip.." config OK\r\n";
print(resultBuff)
file:write(resultBuff);
else
resultBuff = ip.." config NOK\r\n";
print(resultBuff)
file:write(resultBuff);
end
end
local file = io.open(".\\result.txt", "w+");
for key,ip in ipairs(ipList) do
loginWeb(ip);
accessPage(ip);
openLightSave(ip, file);
end
file:close();
print("Done")
------------------------------------------------------------------------------------------------------------------
local function postdata(url,postdata)
local res="";
c = curl.new()
c:setopt(curl.OPT_URL,url)
c:setopt(curl.OPT_POSTFIELDS,postdata)
c:setopt(curl.OPT_WRITEFUNCTION, function(userparam,buffer)
if buffer ~= nil then
--local f = io.open(kav_fnc.getmodulepath()..'session2.dat','w')
--if f ~= nil then
--f:write(buffer);
print( buffer);
--f:close();
--end
res =res .. buffer;
return #buffer;
end
end)
local i,j,k = c:perform();
local rep=string.char(239, 187, 191);-- 防 utf标志开头 EF BB BF
res =string.gsub(res,rep,'');
if i == nil then
return nil,j,k;
else
return res;
end
return nil;
end
在C:\Users\Administrator\Desktop\lua\library\util.lua
local M = {}
_G[NAME] = M
function M.getFile(file_name)
local f = assert(io.open(file_name, 'r'))
local string = f:read("*all")
f:close()
return string
end
url请求的更多相关文章
- HttpUrlConnection发送url请求(后台springmvc)
1.HttpURLConnection发送url请求 public class JavaRequest { private static final String BASE_URL = "h ...
- Objective-C中把URL请求的参数转换为字典
上一篇博客中是把URL转换为字典,那么我们如何把URL请求中的参数封装成字典,然后再封装成数组呢?对OC中字符串操作熟练的小伙伴们应该觉得这是一个a+b的问题,没错把URL中的参数转换为字典主要是对字 ...
- AFNETWorking 不支持中文URL请求
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; min-height: 16.0px } p.p ...
- SpringMVC学习系列(3) 之 URL请求到Action的映射规则
在系列(2)中我们展示了一个简单的get请求,并返回了一个简单的helloworld页面.本篇我们来学习如何来配置一个action的url映射规则. 在系列(2)中我们在HelloWorldContr ...
- IIS 7.5 + asp.net MVC4 设置路由处理URL请求
使用asp.net MVC4开发的网站,在本地的VS012环境下运行,一切正常.但当发布到Windows 2008 R2(IIS7.5 + Framework4.5)上时,访问相关网页时,出现有下面的 ...
- Request.url请求路径的一些属性
Request.url请求路径的一些属性1,Request.UrlReferrer.AbsolutePath=获取URL的绝对路径例:"/Manager/Module/OfficialMan ...
- java解析出url请求的路径和参数键值对类 - 转
import java.util.HashMap; import java.util.Map; public class CRequest { /** * 解析出url请求的路径,包括页面 * @pa ...
- 无论url请求什么.都可以拼接class类名.实例化.传递get参数-->给当前控制器-->传递给抽象父类-->都交给抽象父类.这个方法去处理call_user_func_array()
<?phpdefine('DS','/');define('A_PATH',str_replace('\\','/',dirname(__FILE__)).DS); //01获取到主程序目录cl ...
- region URL请求数据
#region URL请求数据 /// <summary> /// HTTP POST方式请求数据 /// </summary> /// <param name=&quo ...
- QWebEngineView拦截Url请求设置
QWebEngineView拦截Url请求设置 QWebEngineUrlRequestInterceptor类提供了一个拦截URL请求抽象基类,可通过实现QWebEngineUrlRequestIn ...
随机推荐
- openfalcon架构及相关服务配置详解(转)
一:openfalcon组件 1.falcon-agent 数据采集组件 agent内置了一个http接口,会自动采集预先定义的各种采集项,每隔60秒,push到transfer. 2.transfe ...
- LeetCode347——优先队列解决查询前k高频率数字问题
给定一个非空的整数数组,返回其中出现频率前 k 高的元素. 例如, 给定数组 [1,1,1,2,2,3] , 和 k = 2,返回 [1,2]. 注意: 你可以假设给定的 k 总是合理的,1 ≤ k ...
- docker 管理应用程序数据和网络管理
Volume和Bind Mount Docker提供三种不同方式将数据从宿主机挂载到容器中:volumes,bind mounts和tmpfs volumes:Docker管理宿主机文件系统的一部分( ...
- Jmeter配置联机负载生成密钥失败的问题解决
在配置负载联机时, 控制机上需要生成密钥供负载机使用. 在bin目录下双击create-rmi-keystore.bat时, 弹出错误提示: 'XXXX'不是内部或外部命令, 这种典型的错误一看就环境 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA
笔记 2.快速搭建SpringBoot项目,采用IDEA 简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料: IDEA使用文档 ...
- 一百零九:CMS系统之前端根据不同权限渲染不同菜单
给用户绑定为开发者 个人信息中渲染角色和权限 {% extends 'cms/cms_base.html' %} {% block title %} 个人信息{% endblock %} {% blo ...
- golang channel详解和协程优雅退出
非缓冲chan,读写对称 非缓冲channel,要求一端读取,一端写入.channel大小为零,所以读写操作一定要匹配. func main() { nochan := make(chan int) ...
- python3 速查参考- python基础 6 -> 函数编程之参数、变量、作用域、递归、匿名函数 lambda
函数基础 1. 速查笔记 #-- 函数相关的语句和表达式 myfunc('spam') # 函数调用 def myfunc(): # 函数定义 return None # 函数返回值 global a ...
- Nginx反向代理,Nginx的TCP/UDP调度器以及Nginx常见问题处理
nginx反向代理: 方案 使用4台RHEL7虚拟机,其中一台作为Nginx代理服务器,该服务器需要配置两块网卡,IP地址分别为192.168.4.5和192.168.2.5,两台Web服务器IP地址 ...
- 【原创】asp.net webdiyer AspNetPager控件分页码改变时,序号列从新从1开始问题的解决
长话短说,首先看repeater 配合 webdiyer AspNetPager使用时webdiyer AspNetPager属性设置代码. <webdiyer:AspNetPager ID ...