1.打開終端執行如下命令安裝最新版本brew html
brew的做用是一個linux系統的應用類庫中心,能夠經過brew的指令集進行 查詢 下載 安裝 卸載linux
/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
luarocks install luasocket
4.lua學習筆記git
爲何要用lua語言,由於最近作輔助的開發工具都支持lua腳本寫的插件,還有它能垮平臺,內存佔用小。c語言直接開發的。運行速度也很快。github
搭建完畢開發環境後咱們只須要用 luarocks指令來查找安裝咱們須要的類庫 sql
mac打開終端:json
luarocks search luasocket 查詢庫 luasocketruby
luarocks install luasocket 默認安裝最新版本luasocketapp
luarocks search skjson 查詢庫 skjsoncurl
luarocks install skjson 默認安裝最新版本skjsonsocket
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" then 24 for k, v in pairs(response_headers) do 25 print(k, v) 26 end 27 end 28 29 print("Response body:") 30 if type(response_body) == "table" then 31 print(table.concat(response_body)) 32 else 33 print("Not a table:", type(response_body)) 34 end 35 --local tabledata = --table格式的數據-- 36 local jsondata = json.encode (response_body, { indent = true }) 37 print(jsondata)
打印結果
1 200 connection close content-type text/html;charset=utf-8 transfer-encoding chunked date Sun, 30 Jun 2019 09:02:32 GMT Response 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"]