我正在尝试将数据发布到API。我每次都在建立请求。我正在向wrk.format()方法中添加标题。虽然标头类型为string,但头文件不接受事件。
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))有人能帮我吗?
提前谢谢。
发布于 2022-10-26 12:54:21
您需要将整个字典传递给format函数
return wrk.format("POST", "/api/", headers ,data)在我的情况下,标题看起来如下:
headers = {}
headers["Content-Type"] = "application/json"https://stackoverflow.com/questions/52061251
复制相似问题