Lua 不接受wrk.format格式的标题
我正在尝试将数据发布到API。我每次都在构建请求。我正在为Lua 不接受wrk.format格式的标题,lua,http-headers,benchmarking,wrk,Lua,Http Headers,Benchmarking,Wrk,我正在尝试将数据发布到API。我每次都在构建请求。我正在为wrk.format()方法添加标题。虽然标头类型为字符串,但标头不接受事件 headers = {} s = {} request = function() headers["Authorization"] = "key" for name, value in pairs(headers) do s[1] = string.format("%s: %s", name, value) end print(s[1])
wrk.format()
方法添加标题。虽然标头类型为字符串,但标头不接受事件
headers = {}
s = {}
request = function()
headers["Authorization"] = "key"
for name, value in pairs(headers) do
s[1] = string.format("%s: %s", name, value)
end
print(s[1])
print(type(s[1])
return wrk.format("POST", "/api/", s[1] ,data)
end
抛出错误:
PANIC: unprotected error in call to Lua API ([string "wrk"]:0: attempt to index field 'headers' (a string value))
有人能帮我吗
提前感谢。第三个参数必须是表
标题。您传递了一个字符串s[1]
。正确示例:wrk.format(“POST”、“/api/”、{[“Authorization”]=“key”},data)
如果我使用上述语法。甚至是投掷错误。错误参数#1到'len'(应为字符串,Get table))wrk.format(..,..,body)
的第四个参数必须是字符串。您的数据可能是一个表。