函数:httpPost 提交网页数据

函数名称:提交网页数据

函数功能:以 post 方式提交数据获取网页返回信息

函数方法

str = httpPost(url,data,options)

参数 类型 必填 说明
url string 访问的网页地址 URL
data string 要提交的 Post 参数数据
options table 仅 TSLib v1.2.8 及其以上版本支持,操作参数

options 参数介绍

参数 类型 必填 说明
tstab number 参数需要写为 1,不可修改
timeOut number 超时时间,不写默认为 5 秒
urlEnCode boolean 仅 TSLib v1.2.8 及其以上版本支持
是否对 URL 进行编码。默认 false
false - 不进行编码,true - 进行编码
返回值 类型 说明
str string/boolean 成功返回网页内容,失败返回 false

函数用例

require "TSLib"--使用本函数库必须在脚本开头引用并将文件放到设备 lua 目录下
local ts = require "ts"
local json = ts.json
local url = "http://openapi.touchsprite.com/api/openapi"
device = getDeviceID()
local myTable = {}
table.insert(myTable, device)
-- key 需要替换成自己的 Key
local data = [[{
"action": "getAuth",
"key":"T4GrIwHvUHMgMpb4lmypgdmt111T1IGPxeC5hPqxgCgpMBzy2lpx4Y82ScXpxwp8", 
"valid": "3600",
"devices": ]] .. json.encode(myTable) .. [[,
"time": ]] .. os.time() .. [[
}]]
local options = {
    ["tstab"] = 1, -- 必填项
    ["timeOut"] = 90,
    ["urlEnCode"] = false
}
str = httpPost(url, data,options)
if str and str ~= "" then
    dialog(str)
end
Copyright 北京帮你玩科技有限公司 2024 all right reserved,powered by Gitbook该文章修订时间: 2025-04-14 22:09:05

results matching ""

    No results matching ""