实用工具

HttpPost

发送 POST 请求并返回响应正文。

语法

HttpPost(context: any, url: string, body?: string, contentTypeOrCompatibility?: string | number | boolean, headersOrContentType?: table | string, headers?: table): string

参数

名称类型描述
contextany调用方法样式帮助器时提供的自身或上下文参数。
urlstring要连接的 HTTP 或 WebSocket URL。
body?string请求正文随 HTTP 请求一起发送。
contentTypeOrCompatibility?string | number | boolean旧版 HttpPost 签名的内容类型或兼容性标志。
headersOrContentType?table | string标头表或内容类型值,具体取决于调用样式。
headers?table随请求一起发送的 HTTP 标头。

返回值

名称类型描述
bodystringHTTP 响应正文。

说明

发送 POST 请求并返回响应正文。

使用 6 个参数调用: context, url, body, contentTypeOrCompatibility, headersOrContentType, headers。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 body (string)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

使用占位值的示例调用。

local result = HttpPost(nil, "example", "example", "example", "example", {})
print(result)