XQuery/基本身份验证
外观
< XQuery
您希望在安全网络(例如安全 Intranet 或 SSL 连接)上使用非常基本的身份验证过程。
我们将使用 base64 编码和解码工具来生成正确的字符串。
xquery version "1.0";
let $user := 'Aladdin'
let $password := 'open sesame'
let $credentials := concat($user, ':', $password)
let $encode := util:string-to-binary($credentials)
return
<results>
<user>{$user}</user>
<password>{$password}</password>
<encode>{$encode}</encode>
</results>
返回值如下
<results>
<user>Aladdin</user>
<password>open sesame</password>
<encode>QWxhZGRpbjpvcGVuIHNlc2FtZQ==</encode>
</results>
xquery version "1.0";
declare function local:basic-get-http($uri,$username,$password) {
let $credentials := concat($username,":",$password)
let $credentials := util:string-to-binary($credentials)
let $headers :=
<headers>
<header name="Authorization" value="Basic {$credentials}"/>
</headers>
return httpclient:get(xs:anyURI($uri),false(), $headers)
};
let $host := "https://127.0.0.1:8080"
let $path := "/exist/rest/db/apps/terms/data/1.xml"
let $uri := concat($host, $path)
let $user := 'my-login'
let $password := 'my-password'
return local:basic-get-http($uri,$username,$password)
- https://en.wikipedia.org/wiki/Basic_access_authentication 维基百科关于基本身份验证的条目