0
Follow
0
View

Groovy rest client without libraries with basic authentication

dongfeng19811020 注册会员
2023-01-24 20:48

https://en.wikipedia.org/wiki/Basic_access_authentication

In basic HTTP authentication, a request contains a header field in the form of

Authorization: Basic 

where is the Base64 encoding of ID and password joined by a single colon :.

in groovy it could look like this:

def user = ...
def pass = ...
def auth = "${user}:${pass}".bytes.encodeBase64()
connection.setRequestProperty("Authorization", "Basic ${auth}")

About the Author

Question Info

Publish Time
2023-01-24 20:48
Update Time
2023-01-24 20:48