← 返回博客列表
发布于 2023.02.06 15:31:42 · 约 114 字

[skynet] http发post

使用httpc.post. 又或者httpc.request

水篇文章, 如果你在不知道 [如何用skynet发送http的post请求] 的情况下. 看到了本文, 那么以下的思路对你会有帮助

关于如何知道是这个方法

skynet/test目录下有个testhttp.lua文件,这里有如何发http请求,但只有get没有post. 那就通过httpc.get代码跳转到httpc.lua看下源码, 就会找到httpc.post.

function httpc.post(host, url, form, recvheader)
	local header = {
		["content-type"] = "application/x-www-form-urlencoded"
	}
	local body = {}
	for k,v in pairs(form) do
		table.insert(body, string.format("%s=%s",escape(k),escape(v)))
	end

	return httpc.request("POST", host, url, recvheader, header, table.concat(body , "&"))
end

如果httpc.post数据不符合使用需求, 如header不对, 那就直接使用httpc.request吧