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

问题描述 投票:0回答:1

我有以下部分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")

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

lua
1个回答
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请求

© www.soinside.com 2019 - 2024. All rights reserved.