如何在Lua中执行基本身份验证

时间:2019-10-24 06:06:11

标签: lua

我有以下部分lua脚本。

local config_string = [===[

]===]

local config = LuaConfig:new(config_string)
local request = LuaHttpRequest:new(config, "HTTP")

local username = "sss"
local password = "xxx"


request:set_header("Content-Type", "multipart/form-data")
request:set_header("Accept","application/json")

request:set_body("{\"RecordTitle\": { \"Value\": \"test vinay 344\"  }, \"RecordRecordType\": \"2\", \"Fields\": { \"RoadSurface\" { \"Value\": \"smooth\" } } }")

request:set_url("http://ddddddd/CMServiceAPI/Record")

我如何执行基本身份验证?

1 个答案:

答案 0 :(得分:0)

我不知道您使用哪个库,但是像这样:

local username = "sss"
local password = "xxx"

local mime = require("mime")

request:set_header("authentication", "Basic " .. (mime.b64(username ..":" .. password)) )
request:set_header("content-type", "application/json" )

最后使用POST请求