函数:ts.httpPost 发送 httpPOST 请求

函数名称:ts.httpPost

函数功能:发送 http POST 类型 请求

iOS 函数方法

status_resp, header_resp,body_resp = ts.httpPost(urlL,header_send,body_send,encode)

参数 类型 必填 说明
url string 请求 URL
header_send table 请求头部内容,本参数必须与请求体一起填写
body_send table 请求内容,本参数必须与头部一起填写
encode boolean 仅 ts.so v1.4.0 及其以上版本支持,
是否对 URL 进行编码,默认是 false,true - 对 URL 进行编码
返回值 类型 说明
status_resp number HTTP 状态码
header_resp string 返回头部
body_resp string 返回内容

Android 函数方法

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

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

table 参数介绍

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

函数用例

--iOS 函数用例
local ts = require("ts")
header_send = {typeget = "ios"}
body_send = {msg = "hello"}
ts.setHttpsTimeOut(60)
status_resp,header_resp, body_resp  = ts.httpPost("http://api.qingyunke.com/api.php?msg=123&key=free", header_send, body_send,true)
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.httpPost("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 函数将此段代码编码后重新运行代码再试下。

  • 如果想上传图片或者文件可以使用函数: imageBase64编码后进行上传。

Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""