-- 这个是常量设置为目前我们要调试的 mobox3 服务器的IP+PORT
|
MOBOX3 = "http://124.71.2.100:5103"
|
|
function call_mobox_epi( api_url, post_data )
|
-- 将 POST 数据编码为 JSON 格式
|
local post_data_json = json.encode(post_data)
|
-- 创建一个表来存储响应数据
|
local response_body = {}
|
|
local chunks = {}
|
local sink = ltn12.sink.table(chunks)
|
|
-- 发送 HTTP POST 请求
|
local result, code, headers, status_line = http.request{
|
url = api_url,
|
method = "POST",
|
headers = {
|
["Content-Type"] = "application/json",
|
["Content-Length"] = #post_data_json
|
},
|
source = ltn12.source.string(post_data_json),
|
sink = sink
|
}
|
local response_body = table.concat(chunks)
|
|
-- 检查请求是否成功
|
local err_msg
|
if code == 200 then
|
local response = json.decode( response_body )
|
if response.err_code == 0 then
|
if ( response.result.ret_parameter_num == 1 ) then
|
return response.result.code, response.result.value
|
else
|
return response.result.code, response.result.value, response.result.value2
|
end
|
end
|
err_msg = "mobox3 MOBOX-Lua EPI script error!"..response.err_msg
|
else
|
err_msg = "Failed to post data. HTTP code: " .. code
|
end
|
return 1, err_msg
|
end
|