函数:ts.httpGet 发送 httpGET 请求

函数名称:发送 httpGET 请求

函数功能:发送 httpGET 类型请求

iOS 函数方法

status_resp, header_resp,body_resp = ts.httpGet(url, header_send, body_send);

参数 类型 必填 说明
url string 请求 URL
header_send table 请求头部内容,本参数必须与请求体一起填写
body_send table 请求内容,本参数必须与头部一起填写
返回值 类型 说明
status_resp number HTTP 状态码,成功返回 200
header_resp string 返回头部
body_resp string 返回内容

Android 函数方法

status_resp, header_resp,body_resp = ts.httpGet(url,tab)

参数 类型 必填 说明
url string 请求 URL
tab table table 参数

table 参数介绍

参数 类型 必填 说明
tstab string 只能为 tstab,不可修改
header_send table 请求头部内容,本参数必须与请求体一起填写
body_send table 请求内容,本参数必须与头部一起填写
format string 仅支持 v1.1.4 及其以上版本 ts.so,
不写默认不对返回值进行转码,
utf8 - 对 body_resp 进行 utf-8 格式转码,
gbk - 对 body_resp 进行 gbk 格式转码
返回值 类型 说明
status_resp number HTTP 状态码,成功返回 200
header_resp string 返回头部
body_resp string 返回内容

函数用例

--iOS 脚本实例
local ts = require("ts")
header_send = {typeget = "ios"}
body_send = {id = "687"}
ts.setHttpsTimeOut(60)
status_resp, header_resp,body_resp = ts.httpGet("http://helpdoc.touchsprite.com", header_send, body_send)
dialog(status_resp,0)
dialog(header_resp,0)
dialog(body_resp,0)
--Android 脚本实例
local ts = require("ts")
--format 参数仅支持 Android ts.so v1.1.4 及其以上版本
--tstab = "tstab" 此参数不能修改
tab = {tstab = "tstab",header_send = {typeget = "android"} , body_send = {id = "687"} ,format ="gbk" }
code,header_resp, body_resp = ts.httpGet("http://whois.pconline.com.cn/ip.jsp",tab)
dialog(code,0)
dialog(header_resp,0)
dialog(body_resp,0)

注意事项

  • 如果参数中有类似 “%E8%A7%A6%E5%8A%A8%E7%B2%BE%E7%81%B5” 的参数并且运行代码后发现和网络请求的结果不显示,请使用 urlDecoder 函数将此段代码编码后重新运行代码再试下。
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""