java - How to set username and password using RESTEasy client builder? -
i have url needs authentication (like browser pop appears asking username , password.)
generally, can use following format achieve this:
http://username:password@url.com
using resteasy client builder
client client = clientbuilder.newclient(); webtarget target = client.target("http://url.com");
how achieve without having construct http://username:password@url.com
myself? i've seen if there methods use set no luck. i'm not sure how these credentials passed, headers, cookies etc..
looks basic authentication. if that's case, need set authorization
header basic base64encode(username:password)
.
for example:
string credentials = "username:password" string base64encoded = base64.getencoder().encodetostring(credentials.getbytes()); response response = target.request() .header(httpheaders.authorization, "basic " + base64encoded)....
the base64
class used java 8. if you're not using java 8, there libraries have base64 support. prior java 8, there's com.sun
internal base64
class, it's advised not use those.
if want run quick test (and don't have java 8 or don't want go looking lib), can go this site , type in username:password
, encode it, copy , paste code.
for example:
base64encode(username:password) == dxnlcm5hbwu6cgfzc3dvcmq=
Comments
Post a Comment