博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MacOS下brew的安装和使用 lua环境搭建 lua http请求
阅读量:4507 次
发布时间:2019-06-08

本文共 2659 字,大约阅读时间需要 8 分钟。

 lua环境搭建

1.打开终端执行以下命令安装最新版本brew 

brew的作用是一个linux系统的应用类库中心,可以通过brew的指令集进行 查询 下载 安装 卸载

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 3.使用luarocks安装luasocket https://blog.csdn.net/fnzsjt/article/details/41803381?utm_source=blogxgwz5
  1.   luarocks install luasocket

  4.lua学习笔记

   为什么要用lua语言,因为最近做辅助的开发工具都支持lua脚本写的插件,还有它能垮平台,内存占用小。c语言直接开发的。运行速度也很快。

  搭建完毕开发环境后我们只需要用 luarocks指令来查找安装我们需要的类库 

 mac打开终端:

              luarocks search luasocket 查询库 luasocket

              luarocks install luasocket 默认安装最新版本luasocket

             luarocks search skjson 查询库 skjson

              luarocks install skjson 默认安装最新版本skjson

           

5.lua http请求

         

1 local http=require("socket.http") 2 local ltn12 = require("ltn12") 3 local json = require ("dkjson") 4 local http=require("socket.http"); 5 local request_body = [[account=13983918072&deviceKey=fba71fd5ff7f4eb28c84a574b00c9989]] 6 local response_body = {} 7  8 local res, code, response_headers = http.request{ 9     url = "http://192.168.1.104:8080/autoDrainageServlet/AUserTokenVerify",10     method = "POST",11     headers =12     {13         ["Content-Type"] = "application/x-www-form-urlencoded";14         ["Content-Length"] = #request_body;15     },16     source = ltn12.source.string(request_body),17     sink = ltn12.sink.table(response_body),18 }19 20 print(res)21 print(code)22 23 if type(response_headers) == "table" then24     for k, v in pairs(response_headers) do25         print(k, v)26     end27 end28 29 print("Response body:")30 if type(response_body) == "table" then31     print(table.concat(response_body))32 else33     print("Not a table:", type(response_body))34 end35 --local tabledata  = --table格式的数据--36 local jsondata =  json.encode (response_body, { indent = true })37 print(jsondata)

打印结果 

1200connection    closecontent-type    text/html;charset=utf-8transfer-encoding    chunkeddate    Sun, 30 Jun 2019 09:02:32 GMTResponse body:{
"pointAccount":"13983918072","Msg":"验证成功","historyFreezeTimes":"0","deviceKey":"fba71fd5ff7f4eb28c84a574b00c9989","Success":"1","useStatus":"离线","token":"d1451f5f430d49d3b055596e5859316b","createData":"2019-06-19 08:48:23.0","freeze":"未冻结","dianzan":"否","addManyTimesChangeQQ":"6","id":"168","todayVerifyFailTimes":"0"}["{\"pointAccount\":\"13983918072\",\"Msg\":\"验证成功\",\"historyFreezeTimes\":\"0\",\"deviceKey\":\"fba71fd5ff7f4eb28c84a574b00c9989\",\"Success\":\"1\",\"useStatus\":\"离线\",\"token\":\"d1451f5f430d49d3b055596e5859316b\",\"createData\":\"2019-06-19 08:48:23.0\",\"freeze\":\"未冻结\",\"dianzan\":\"否\",\"addManyTimesChangeQQ\":\"6\",\"id\":\"168\",\"todayVerifyFailTimes\":\"0\"}\n"]

 

 

 

 

转载于:https://www.cnblogs.com/xiaoliao/p/11108436.html

你可能感兴趣的文章
servlet.txt笔记
查看>>
jquery设置select选中
查看>>
今天说一下DML触发器的顺序
查看>>
Memcached学习(一)--网络模型
查看>>
FragmentTransaction add 和 replace 区别 转
查看>>
html5及css3开发性能问题
查看>>
使用python发送邮件
查看>>
【转】java虚拟机内存原型
查看>>
2018年最新Java面试题及答案整理(持续完善中…)
查看>>
什么是构造函数,什么是析构函数,作用是什么。
查看>>
C# 想要程序文件移动 而数据保持相对位置
查看>>
功能连接分析论文
查看>>
消息称各中央单位落户北京指标今年压缩17%
查看>>
记一次IIS站点出错的解决过程
查看>>
jQuery 效果方法
查看>>
STM32物联网通信WIFI
查看>>
java反射案例详解
查看>>
MAGENTO 与 reindexer
查看>>
Oracle笔记之——常用的函数及脚本
查看>>
SQLServer2008 关于Having
查看>>